Class: Discorb::Guild

Inherits:
DiscordModel show all
Includes:
ChannelContainer
Defined in:
lib/discorb/guild.rb

Overview

Represents a guild in the Discord.

Defined Under Namespace

Classes: Ban, VanityInvite, Widget

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ChannelContainer

#news_channels, #stage_channels, #text_channels, #voice_channels

Methods inherited from DiscordModel

#==, #eql?

Instance Attribute Details

#afk_channelDiscorb::VoiceChannel? (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/guild.rb', line 107

#afk_timeoutInteger (readonly)

Returns The AFK timeout of the guild.

Returns:

  • (Integer)

    The AFK timeout of the guild.



21
22
23
# File 'lib/discorb/guild.rb', line 21

def afk_timeout
  @afk_timeout
end

#approximate_member_countInteger (readonly)

Returns The approxmate amount of members in the guild.

Returns:

  • (Integer)

    The approxmate amount of members in the guild.



73
74
75
# File 'lib/discorb/guild.rb', line 73

def approximate_member_count
  @approximate_member_count
end

#approximate_presence_countInteger (readonly)

Returns The approxmate amount of non-offline members in the guild.

Returns:

  • (Integer)

    The approxmate amount of non-offline members in the guild.



75
76
77
# File 'lib/discorb/guild.rb', line 75

def approximate_presence_count
  @approximate_presence_count
end

#availableBoolean (readonly) Also known as: available?

Returns Whether the guild is available.

Returns:

  • (Boolean)

    Whether the guild is available.



99
100
101
# File 'lib/discorb/guild.rb', line 99

def available
  @available
end

Returns:

  • (Discorb::Asset)

    The banner of the guild.

  • (nil)

    If the guild does not have a banner.



62
63
64
# File 'lib/discorb/guild.rb', line 62

def banner
  @banner
end

#channelsDiscorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel} (readonly)

Returns A dictionary of channels in the guild.

Returns:



48
49
50
# File 'lib/discorb/guild.rb', line 48

def channels
  @channels
end

#default_message_notifications:all_messages, :only_mentions (readonly)

Returns The default message notification level of the guild.

Returns:

  • (:all_messages, :only_mentions)

    The default message notification level of the guild.



86
87
88
# File 'lib/discorb/guild.rb', line 86

def default_message_notifications
  @default_message_notifications
end

#descriptionString (readonly)

Returns The description of the guild.

Returns:

  • (String)

    The description of the guild.



59
60
61
# File 'lib/discorb/guild.rb', line 59

def description
  @description
end

#discovery_splashDiscorb::Asset (readonly)

Returns The discovery splash of the guild.

Returns:



15
16
17
# File 'lib/discorb/guild.rb', line 15

def discovery_splash
  @discovery_splash
end

#emojisDiscorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji} (readonly)

Returns A dictionary of custom emojis in the guild.

Returns:



26
27
28
# File 'lib/discorb/guild.rb', line 26

def emojis
  @emojis
end

#explicit_content_filter:disabled_in_text, ... (readonly)

Returns The explict content filter level of the guild.

Returns:

  • (:disabled_in_text, :members_without_roles, :all_members)

    The explict content filter level of the guild.



88
89
90
# File 'lib/discorb/guild.rb', line 88

def explicit_content_filter
  @explicit_content_filter
end

#featuresArray<Symbol> (readonly)

Returns features that are enabled in the guild.

Returns:

  • (Array<Symbol>)

    features that are enabled in the guild.

See Also:



29
30
31
# File 'lib/discorb/guild.rb', line 29

def features
  @features
end

#iconDiscorb::Asset (readonly)

Returns The icon of the guild.

Returns:



41
42
43
# File 'lib/discorb/guild.rb', line 41

def icon
  @icon
end

#idDiscorb::Snowflake (readonly)

Returns ID of the guild.

Returns:



9
10
11
# File 'lib/discorb/guild.rb', line 9

def id
  @id
end

#joined_atTime (readonly)

Returns Time that representing when bot has joined the guild.

Returns:

  • (Time)

    Time that representing when bot has joined the guild.



35
36
37
# File 'lib/discorb/guild.rb', line 35

def joined_at
  @joined_at
end

#largeBoolean (readonly) Also known as: large?

Returns Whether the guild is large.

Returns:

  • (Boolean)

    Whether the guild is large.



93
94
95
# File 'lib/discorb/guild.rb', line 93

def large
  @large
end

#max_presencesInteger (readonly)

Returns Number of online members in the guild.

Returns:

  • (Integer)

    Number of online members in the guild.



54
55
56
# File 'lib/discorb/guild.rb', line 54

def max_presences
  @max_presences
end

#max_video_channel_usersInteger (readonly)

Returns The maximum amount of users in a video channel.

Returns:

  • (Integer)

    The maximum amount of users in a video channel.



71
72
73
# File 'lib/discorb/guild.rb', line 71

def max_video_channel_users
  @max_video_channel_users
end

#meDiscorb::Member (readonly)

Returns The client's member in the guild.

Returns:



# File 'lib/discorb/guild.rb', line 107

#member_countInteger (readonly)

Returns The amount of members in the guild.

Returns:

  • (Integer)

    The amount of members in the guild.



39
40
41
# File 'lib/discorb/guild.rb', line 39

def member_count
  @member_count
end

#membersDiscorb::Dictionary{Discorb::Snowflake => Discorb::Member} (readonly)

Note:

You must enable GUILD_MEMBERS intent to use this method.

Returns A dictionary of members in the guild.

Returns:



46
47
48
# File 'lib/discorb/guild.rb', line 46

def members
  @members
end

#mfa_level:none, :elevated (readonly)

Returns The MFA level of the guild.

Returns:

  • (:none, :elevated)

    The MFA level of the guild.



31
32
33
# File 'lib/discorb/guild.rb', line 31

def mfa_level
  @mfa_level
end

#nameString (readonly)

Returns The name of the guild.

Returns:

  • (String)

    The name of the guild.



11
12
13
# File 'lib/discorb/guild.rb', line 11

def name
  @name
end

#nsfw_level:default, ... (readonly)

Returns The nsfw level of the guild.

Returns:

  • (:default, :explicit, :safe, :age_restricted)

    The nsfw level of the guild.



79
80
81
# File 'lib/discorb/guild.rb', line 79

def nsfw_level
  @nsfw_level
end

#ownerBoolean (readonly) Also known as: owner?

Returns Whether the client is the owner of the guild.

Returns:

  • (Boolean)

    Whether the client is the owner of the guild.



90
91
92
# File 'lib/discorb/guild.rb', line 90

def owner
  @owner
end

#owner_idDiscorb::Snowflake (readonly)

Returns ID of the guild owner.

Returns:



17
18
19
# File 'lib/discorb/guild.rb', line 17

def owner_id
  @owner_id
end

#permissionsDiscorb::Permission (readonly)

Returns The bot's permission in the guild.

Returns:



19
20
21
# File 'lib/discorb/guild.rb', line 19

def permissions
  @permissions
end

#preferred_localeSymbol (readonly)

Note:

This modifies the language code, - will be replaced with _.

Returns The preffered language of the guild.

Returns:

  • (Symbol)

    The preffered language of the guild.



69
70
71
# File 'lib/discorb/guild.rb', line 69

def preferred_locale
  @preferred_locale
end

#premium_subscription_countInteger (readonly)

Returns The amount of premium subscriptions (Server Boosts) the guild has.

Returns:

  • (Integer)

    The amount of premium subscriptions (Server Boosts) the guild has.



66
67
68
# File 'lib/discorb/guild.rb', line 66

def premium_subscription_count
  @premium_subscription_count
end

#premium_tierInteger (readonly)

Returns The premium tier (Boost Level) of the guild.

Returns:

  • (Integer)

    The premium tier (Boost Level) of the guild.



64
65
66
# File 'lib/discorb/guild.rb', line 64

def premium_tier
  @premium_tier
end

#presencesDiscorb::Dictionary{Discorb::User => Discorb::Presence} (readonly)

Returns A dictionary of presence in the guild.

Returns:



52
53
54
# File 'lib/discorb/guild.rb', line 52

def presences
  @presences
end

#public_updates_channelDiscorb::TextChannel? (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (Discorb::TextChannel)

    The public updates channel (#moderator-only) for this guild.

  • (nil)

    The object wasn't cached.



# File 'lib/discorb/guild.rb', line 107

#rolesDiscorb::Dictionary{Discorb::Snowflake => Discorb::Role} (readonly)

Returns A dictionary of roles in the guild.

Returns:



23
24
25
# File 'lib/discorb/guild.rb', line 23

def roles
  @roles
end

#rules_channelDiscorb::TextChannel? (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/guild.rb', line 107

#scheduled_eventsDictionary{Discorb::Snowflake => Discorb::ScheduledEvent} (readonly) Also known as: events

Returns A dictionary of scheduled events in the guild.

Returns:



102
103
104
# File 'lib/discorb/guild.rb', line 102

def scheduled_events
  @scheduled_events
end

#splashDiscorb::Asset (readonly)

Returns The splash of the guild.

Returns:



13
14
15
# File 'lib/discorb/guild.rb', line 13

def splash
  @splash
end

#stage_instancesDiscorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance} (readonly)

Returns A dictionary of stage instances in the guild.

Returns:



82
83
84
# File 'lib/discorb/guild.rb', line 82

def stage_instances
  @stage_instances
end

#system_channelDiscorb::TextChannel? (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (Discorb::TextChannel)

    The system message channel for this guild.

  • (nil)

    The object wasn't cached.



# File 'lib/discorb/guild.rb', line 107

#system_channel_flagsDiscorb::SystemChannelFlag (readonly)

Returns The flag for the system channel.

Returns:



33
34
35
# File 'lib/discorb/guild.rb', line 33

def system_channel_flags
  @system_channel_flags
end

#threadsDiscorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel} (readonly)

Returns A dictionary of threads in the guild.

Returns:



50
51
52
# File 'lib/discorb/guild.rb', line 50

def threads
  @threads
end

#unavailableBoolean (readonly)

Returns Whether the guild is unavailable.

Returns:

  • (Boolean)

    Whether the guild is unavailable.



37
38
39
# File 'lib/discorb/guild.rb', line 37

def unavailable
  @unavailable
end

#vanity_url_codeString? (readonly)

Returns:

  • (String)

    The vanity invite URL for the guild.

  • (nil)

    If the guild does not have a vanity invite URL.



57
58
59
# File 'lib/discorb/guild.rb', line 57

def vanity_url_code
  @vanity_url_code
end

#verification_level:none, ... (readonly)

Returns The verification level of the guild.

Returns:

  • (:none, :low, :medium, :high, :very_high)

    The verification level of the guild.



84
85
86
# File 'lib/discorb/guild.rb', line 84

def verification_level
  @verification_level
end

#voice_statesDiscorb::Dictionary{Discorb::User => Discorb::VoiceState} (readonly)

Returns A dictionary of voice states in the guild.

Returns:



43
44
45
# File 'lib/discorb/guild.rb', line 43

def voice_states
  @voice_states
end

#welcome_screenDiscorb::WelcomeScreen (readonly)

Returns The welcome screen of the guild.

Returns:



77
78
79
# File 'lib/discorb/guild.rb', line 77

def welcome_screen
  @welcome_screen
end

#widget_enabledBoolean (readonly) Also known as: widget_enabled?

Returns Whether the guild enabled the widget.

Returns:

  • (Boolean)

    Whether the guild enabled the widget.



96
97
98
# File 'lib/discorb/guild.rb', line 96

def widget_enabled
  @widget_enabled
end

Class Method Details

Returns a banner url from the guild's ID.

Parameters:

  • guild_id (#to_s)

    The ID of the guild.

  • style (:shield, :banner1, :banner2, :banner3, :banner4) (defaults to: :banner)

    The style of the banner.

Returns:

  • (String)

    The url of the banner.



1810
1811
1812
# File 'lib/discorb/guild.rb', line 1810

def banner(guild_id, style: :banner)
  "#{Discorb::API_BASE_URL}/guilds/#{guild_id}/widget.png&style=#{style}"
end

Instance Method Details

#ban_member(member, delete_message_days: 0, reason: nil) ⇒ Async::Task<Discorb::Guild::Ban>

Ban a member from the guild.

Parameters:

  • member (Discorb::Member)

    The member to ban.

  • delete_message_days (Integer) (defaults to: 0)

    The number of days to delete messages.

  • reason (String) (defaults to: nil)

    The reason for banning the member.

Returns:



1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/discorb/guild.rb', line 1111

def ban_member(member, delete_message_days: 0, reason: nil)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/bans",
            "//guilds/:guild_id/bans",
            :post
          ),
          { user: member.id, delete_message_days: delete_message_days },
          audit_log_reason: reason
        )
        .wait
    Ban.new(@client, self, data)
  end
end

#banned?(user) ⇒ Async::Task<Boolean>

Checks the user was banned from the guild.

Parameters:

Returns:

  • (Async::Task<Boolean>)

    Whether the user was banned.



1097
1098
1099
# File 'lib/discorb/guild.rb', line 1097

def banned?(user)
  Async { !fetch_ban(user).wait.nil? }
end

#create_automod_rule(name, trigger_type, actions, event_type = :message_send, enabled: false, exempt_roles: [], exempt_channels: [], keyword_filter: nil, mention_total_limit: nil, allow_list: nil, presets: nil, reason: nil) ⇒ Async::Task<Discorb::AutoModRule>

Create a new automod rule in the guild.

Parameters:

  • name (String)

    The name of the rule.

  • trigger_type (Symbol)

    The trigger type of the rule. See AutoModRule::TRIGGER_TYPES.

  • actions (Array<Discorb::AutoModRule::Action>)

    The actions of the rule.

  • event_type (Symbol) (defaults to: :message_send)

    The event type of the rule. See AutoModRule::EVENT_TYPES.

  • enabled (Boolean) (defaults to: false)

    Whether the rule is enabled or not.

  • exempt_roles (Array<Discorb::Role>) (defaults to: [])

    The roles that are exempt from the rule.

  • exempt_channels (Array<Discorb::Channel>) (defaults to: [])

    The channels that are exempt from the rule.

  • keyword_filter (Array<String>) (defaults to: nil)

    The keywords to filter.

  • allow_list (Array<String>) (defaults to: nil)

    Substrings which will be exempt from triggering the preset trigger type.

  • mention_total_limit (Integer) (defaults to: nil)

    The total number of mentions allowed per message.

  • presets (Symbol) (defaults to: nil)

    The preset of the rule. See AutoModRule::PRESET_TYPES.

  • reason (String) (defaults to: nil)

    The reason for creating the rule.

Returns:



1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
# File 'lib/discorb/guild.rb', line 1597

def create_automod_rule(
  name,
  trigger_type,
  actions,
  event_type = :message_send,
  enabled: false,
  exempt_roles: [],
  exempt_channels: [],
  keyword_filter: nil,
  mention_total_limit: nil,
  allow_list: nil,
  presets: nil,
  reason: nil
)
  Async do
    payload = {
      name: name,
      event_type: Discorb::AutoModRule::EVENT_TYPES.key(event_type),
      trigger_type: Discorb::AutoModRule::TRIGGER_TYPES.key(trigger_type),
      metadata: {
        keyword_filter: keyword_filter,
        presets: presets && Discorb::AutoModRule::PRESET_TYPES.key(presets),
        allow_list: allow_list,
        mention_total_limit: mention_total_limit
      },
      actions: actions.map(&:to_hash),
      enabled: enabled,
      exempt_roles: exempt_roles.map(&:id),
      exempt_channels: exempt_channels.map(&:id)
    }

    _resp, data =
      @client.http.request(
        Route.new(
          "/guilds/#{@id}/auto-moderation/rules",
          "//guilds/:guild_id/auto-moderation/rules",
          :post
        ),
        payload,
        audit_log_reason: reason
      )
    Discorb::AutoModRule.new(@client, data)
  end
end

#create_category_channel(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil) ⇒ Async::Task<Discorb::CategoryChannel> Also known as: create_category

Create a new category channel.

Parameters:

  • name (String)

    The name of the channel.

  • position (Integer) (defaults to: nil)

    The position of the channel.

  • permission_overwrites (Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}) (defaults to: nil)

    A list of permission overwrites.

  • parent (Discorb::CategoryChannel) (defaults to: nil)

    The parent of the channel.

  • reason (String) (defaults to: nil)

    The reason for creating the channel.

Returns:



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/discorb/guild.rb', line 658

def create_category_channel(
  name,
  position: nil,
  permission_overwrites: nil,
  parent: nil,
  reason: nil
)
  Async do
    payload = { type: CategoryChannel.channel_type }
    payload[:name] = name
    payload[:position] = position if position
    if permission_overwrites
      payload[
        :permission_overwrites
      ] = permission_overwrites.map do |target, overwrite|
        {
          type: target.is_a?(Role) ? 0 : 1,
          id: target.id,
          allow: overwrite.allow_value,
          deny: overwrite.deny_value
        }
      end
    end
    payload[:parent_id] = parent&.id
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    Channel.make_channel(@client, data)
  end
end

#create_emoji(name, image, roles: []) ⇒ Async::Task<Discorb::CustomEmoji>

Create a custom emoji.

Parameters:

  • name (#to_s)

    The name of the emoji.

  • image (Discorb::Image)

    The image of the emoji.

  • roles (Array<Discorb::Role>) (defaults to: [])

    A list of roles to give the emoji.

Returns:



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/discorb/guild.rb', line 425

def create_emoji(name, image, roles: [])
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/emojis",
            "//guilds/:guild_id/emojis",
            :post
          ),
          {
            name: name,
            image: image.to_s,
            roles: roles.map { |r| Discorb::Utils.try(r, :id) }
          }
        )
        .wait
    @emojis[data[:id]] = CustomEmoji.new(@client, self, data)
  end
end

#create_news_channel(name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil) ⇒ Async::Task<Discorb::NewsChannel>

Create a new news channel.

Parameters:

  • name (String)

    The name of the channel.

  • topic (String) (defaults to: nil)

    The topic of the channel.

  • rate_limit_per_user (Integer) (defaults to: nil)

    The rate limit per user in the channel.

  • slowmode (Integer) (defaults to: nil)

    Alias for rate_limit_per_user.

  • position (Integer) (defaults to: nil)

    The position of the channel.

  • nsfw (Boolean) (defaults to: nil)

    Whether the channel is nsfw.

  • permission_overwrites (Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}) (defaults to: nil)

    A list of permission overwrites.

  • parent (Discorb::CategoryChannel) (defaults to: nil)

    The parent of the channel.

  • reason (String) (defaults to: nil)

    The reason for creating the channel.

Returns:



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# File 'lib/discorb/guild.rb', line 775

def create_news_channel(
  name,
  topic: nil,
  rate_limit_per_user: nil,
  slowmode: nil,
  position: nil,
  nsfw: nil,
  permission_overwrites: nil,
  parent: nil,
  reason: nil
)
  Async do
    payload = { type: NewsChannel.channel_type }
    payload[:name] = name
    payload[:topic] = topic if topic
    rate_limit_per_user ||= slowmode
    payload[
      :rate_limit_per_user
    ] = rate_limit_per_user if rate_limit_per_user
    payload[:position] = position if position
    if permission_overwrites
      payload[
        :permission_overwrites
      ] = permission_overwrites.map do |target, overwrite|
        {
          type: target.is_a?(Role) ? 0 : 1,
          id: target.id,
          allow: overwrite.allow_value,
          deny: overwrite.deny_value
        }
      end
    end
    payload[:nsfw] = nsfw unless nsfw.nil?
    payload[:parent_id] = parent&.id
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    Channel.make_channel(@client, data)
  end
end

#create_role(name = nil, color: nil, hoist: nil, mentionable: nil, reason: nil) ⇒ Async::Task<Discorb::Role>

Create a role in the guild.

Parameters:

  • name (String) (defaults to: nil)

    The name of the role.

  • color (Discorb::Color) (defaults to: nil)

    The color of the role.

  • hoist (Boolean) (defaults to: nil)

    Whether the role should be hoisted.

  • mentionable (Boolean) (defaults to: nil)

    Whether the role should be mentionable.

  • reason (String) (defaults to: nil)

    The reason for creating the role.

Returns:



1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
# File 'lib/discorb/guild.rb', line 1191

def create_role(
  name = nil,
  color: nil,
  hoist: nil,
  mentionable: nil,
  reason: nil
)
  Async do
    payload = {}
    payload[:name] = name if name
    payload[:color] = color.to_i if color
    payload[:hoist] = hoist if hoist
    payload[:mentionable] = mentionable if mentionable
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/roles",
            "//guilds/:guild_id/roles",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    Role.new(@client, self, data)
  end
end

#create_scheduled_event(type, name, description, start_time, end_time = nil, privacy_level: :guild_only, location: nil, channel: nil) ⇒ Async::Task<Discorb::ScheduledEvent>

Create a scheduled event for the guild.

Parameters:

  • type (:stage_instance, :voice, :external)

    The type of event to create.

  • name (String)

    The name of the event.

  • description (String)

    The description of the event.

  • start_time (Time)

    The start time of the event.

  • end_time (Time, nil) (defaults to: nil)

    The end time of the event. Defaults to nil.

  • channel (Discorb::Channel, Discorb::Snowflake, nil) (defaults to: nil)

    The channel to run the event in.

  • location (String, nil) (defaults to: nil)

    The location of the event. Defaults to nil.

  • privacy_level (:guild_only) (defaults to: :guild_only)

    The privacy level of the event. This must be :guild_only.

Returns:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/discorb/guild.rb', line 269

def create_scheduled_event(
  type,
  name,
  description,
  start_time,
  end_time = nil,
  privacy_level: :guild_only,
  location: nil,
  channel: nil
)
  Async do
    payload =
      case type
      when :stage_instance
        unless channel
          raise ArgumentError,
                "channel must be provided for stage_instance events"
        end

        {
          name: name,
          description: description,
          scheduled_start_time: start_time.iso8601,
          scheduled_end_time: end_time&.iso8601,
          privacy_level:
            Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
          channel_id: channel&.id,
          entity_type:
            Discorb::ScheduledEvent::ENTITY_TYPE.key(:stage_instance)
        }
      when :voice
        unless channel
          raise ArgumentError, "channel must be provided for voice events"
        end

        {
          name: name,
          description: description,
          scheduled_start_time: start_time.iso8601,
          scheduled_end_time: end_time&.iso8601,
          privacy_level:
            Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
          channel_id: channel&.id,
          entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:voice)
        }
      when :external
        unless location
          raise ArgumentError,
                "location must be provided for external events"
        end
        unless end_time
          raise ArgumentError,
                "end_time must be provided for external events"
        end

        {
          name: name,
          description: description,
          scheduled_start_time: start_time.iso8601,
          scheduled_end_time: end_time.iso8601,
          privacy_level:
            Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
          entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:external),
          entity_metadata: {
            location: location
          }
        }
      else
        raise ArgumentError, "Invalid scheduled event type: #{type}"
      end
    _resp, event =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/scheduled-events",
            "//guilds/:guild_id/scheduled-events",
            :post
          ),
          payload
        )
        .wait
    Discorb::ScheduledEvent.new(@client, event)
  end
end

#create_stage_channel(name, bitrate: 64, position: nil, permission_overwrites: nil, parent: nil, reason: nil) ⇒ Async::Task<Discorb::StageChannel>

Create a new stage channel.

Parameters:

  • name (String)

    The name of the channel.

  • bitrate (Integer) (defaults to: 64)

    The bitrate of the channel.

  • position (Integer) (defaults to: nil)

    The position of the channel.

  • permission_overwrites (Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}) (defaults to: nil)

    A list of permission overwrites.

  • parent (Discorb::CategoryChannel) (defaults to: nil)

    The parent of the channel.

  • reason (String) (defaults to: nil)

    The reason for creating the channel.

Returns:



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/discorb/guild.rb', line 715

def create_stage_channel(
  name,
  bitrate: 64,
  position: nil,
  permission_overwrites: nil,
  parent: nil,
  reason: nil
)
  Async do
    payload = { type: StageChannel.channel_type }
    payload[:name] = name
    payload[:bitrate] = bitrate * 1000 if bitrate
    payload[:position] = position if position
    if permission_overwrites
      payload[
        :permission_overwrites
      ] = permission_overwrites.map do |target, overwrite|
        {
          type: target.is_a?(Role) ? 0 : 1,
          id: target.id,
          allow: overwrite.allow_value,
          deny: overwrite.deny_value
        }
      end
    end
    payload[:parent_id] = parent&.id
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    Channel.make_channel(@client, data)
  end
end

#create_template(name, description = nil, reason: nil) ⇒ Async::Task<Discorb::GuildTemplate>

Create a new template in the guild.

Parameters:

  • name (String)

    The name of the template.

  • description (String) (defaults to: nil)

    The description of the template.

  • reason (String) (defaults to: nil)

    The reason for creating the template.

Returns:



1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
# File 'lib/discorb/guild.rb', line 1513

def create_template(name, description = nil, reason: nil)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/templates",
            "//guilds/:guild_id/templates",
            :post
          ),
          { name: name, description: description },
          audit_log_reason: reason
        )
        .wait
    GuildTemplate.new(@client, data)
  end
end

#create_text_channel(name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil) ⇒ Async::Task<Discorb::TextChannel>

Create a new text channel.

Parameters:

  • name (String)

    The name of the channel.

  • topic (String) (defaults to: nil)

    The topic of the channel.

  • rate_limit_per_user (Integer) (defaults to: nil)

    The rate limit per user in the channel.

  • slowmode (Integer) (defaults to: nil)

    Alias for rate_limit_per_user.

  • position (Integer) (defaults to: nil)

    The position of the channel.

  • nsfw (Boolean) (defaults to: nil)

    Whether the channel is nsfw.

  • permission_overwrites (Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}) (defaults to: nil)

    A list of permission overwrites.

  • parent (Discorb::CategoryChannel) (defaults to: nil)

    The parent of the channel.

  • reason (String) (defaults to: nil)

    The reason for creating the channel.

Returns:



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/discorb/guild.rb', line 533

def create_text_channel(
  name,
  topic: nil,
  rate_limit_per_user: nil,
  slowmode: nil,
  position: nil,
  nsfw: nil,
  permission_overwrites: nil,
  parent: nil,
  reason: nil
)
  Async do
    payload = { type: TextChannel.channel_type }
    payload[:name] = name
    payload[:topic] = topic if topic
    rate_limit_per_user ||= slowmode
    payload[
      :rate_limit_per_user
    ] = rate_limit_per_user if rate_limit_per_user
    payload[:nsfw] = nsfw if nsfw
    payload[:position] = position if position
    if permission_overwrites
      payload[
        :permission_overwrites
      ] = permission_overwrites.map do |target, overwrite|
        {
          type: target.is_a?(Role) ? 0 : 1,
          id: target.id,
          allow: overwrite.allow_value,
          deny: overwrite.deny_value
        }
      end
    end
    payload[:parent_id] = parent.id if parent
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    payload[:parent_id] = parent&.id
    Channel.make_channel(@client, data)
  end
end

#create_voice_channel(name, bitrate: 64, user_limit: nil, position: nil, permission_overwrites: nil, parent: nil, reason: nil) ⇒ Async::Task<Discorb::VoiceChannel>

Create a new voice channel.

Parameters:

  • name (String)

    The name of the channel.

  • bitrate (Integer) (defaults to: 64)

    The bitrate of the channel.

  • user_limit (Integer) (defaults to: nil)

    The user limit of the channel.

  • position (Integer) (defaults to: nil)

    The position of the channel.

  • permission_overwrites (Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}) (defaults to: nil)

    A list of permission overwrites.

  • parent (Discorb::CategoryChannel) (defaults to: nil)

    The parent of the channel.

  • reason (String) (defaults to: nil)

    The reason for creating the channel.

Returns:



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/discorb/guild.rb', line 600

def create_voice_channel(
  name,
  bitrate: 64,
  user_limit: nil,
  position: nil,
  permission_overwrites: nil,
  parent: nil,
  reason: nil
)
  Async do
    payload = { type: VoiceChannel.channel_type }
    payload[:name] = name
    payload[:bitrate] = bitrate * 1000 if bitrate
    payload[:user_limit] = user_limit if user_limit
    payload[:position] = position if position
    if permission_overwrites
      payload[
        :permission_overwrites
      ] = permission_overwrites.map do |target, overwrite|
        {
          type: target.is_a?(Role) ? 0 : 1,
          id: target.id,
          allow: overwrite.allow_value,
          deny: overwrite.deny_value
        }
      end
    end
    payload[:parent_id] = parent.id if parent
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :post
          ),
          payload,
          audit_log_reason: reason
        )
        .wait
    payload[:parent_id] = parent&.id
    Channel.make_channel(@client, data)
  end
end

#edit_nickname(nickname, reason: nil) ⇒ Async::Task<void> Also known as: edit_nick, modify_nickname

Change nickname of client member.

Parameters:

  • nickname (String)

    The nickname to set.

  • reason (String) (defaults to: nil)

    The reason for changing the nickname.

Returns:

  • (Async::Task<void>)

    The task.



978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
# File 'lib/discorb/guild.rb', line 978

def edit_nickname(nickname, reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@id}/members/@me/nick",
          "//guilds/:guild_id/members/@me/nick",
          :patch
        ),
        { nick: nickname },
        audit_log_reason: reason
      )
      .wait
  end
end

#fetch_active_threadsAsync::Task<Array<Discorb::ThreadChannel>>

Fetch a list of active threads in the guild.

Returns:



832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
# File 'lib/discorb/guild.rb', line 832

def fetch_active_threads
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/threads/active",
            "//guilds/:guild_id/threads/active",
            :get
          )
        )
        .wait
    data[:threads].map { |t| Channel.make_thread(@client, t) }
  end
end

#fetch_audit_logAsync::Task<Discorb::AuditLog>

Fetch audit log of the guild.

Returns:



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/discorb/guild.rb', line 476

def fetch_audit_log
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/audit-logs",
            "//guilds/:guild_id/audit-logs",
            :get
          )
        )
        .wait
    AuditLog.new(@client, data, self)
  end
end

#fetch_automod_rule(id) ⇒ Async::Task<Array<Discord::AutoModRule>>

Fetch the automod rule by ID.

Parameters:

  • id (#to_s)

    The ID of the automod rule.

Returns:

  • (Async::Task<Array<Discord::AutoModRule>>)

    The automod rule.



1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
# File 'lib/discorb/guild.rb', line 1561

def fetch_automod_rule(id)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/auto-moderation/rules/#{id}",
            "//guilds/:guild_id/auto-moderation/rules/:rule_id",
            :get
          )
        )
        .wait
    AutoModRule.new(@client, data)
  end
end

#fetch_automod_rulesAsync::Task<Array<Discorb::AutoModRule>> Also known as: fetch_automod_rule_list

Fetch the automod rules in the guild.

Returns:



1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
# File 'lib/discorb/guild.rb', line 1538

def fetch_automod_rules
  Async do
    _resp, data =
      @client.http.request(
        Route.new(
          "/guilds/#{@id}/auto-moderation/rules",
          "//guilds/:guild_id/auto-moderation/rules",
          :get
        )
      )
    data.map { |d| AutoModRule.new(@client, d) }
  end
end

#fetch_ban(user) ⇒ Async::Task<Discorb::Guild::Ban>, Async::Task<nil>

Fetch a ban in the guild.

Parameters:

Returns:

  • (Async::Task<Discorb::Guild::Ban>)

    The ban.

  • (Async::Task<nil>)

    If the ban is not found.



1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File 'lib/discorb/guild.rb', line 1069

def fetch_ban(user)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/bans/#{user.id}",
            "//guilds/:guild_id/bans/:user_id",
            :get
          )
        )
        .wait
  rescue Discorb::NotFoundError
    nil
  else
    Ban.new(@client, self, data)
  end
end

#fetch_bans(limit = 50, before: nil, after: nil, around: nil) ⇒ Async::Task<Array<Discorb::Guild::Ban>>

Fetch a list of bans in the guild.

Parameters:

  • limit (Integer) (defaults to: 50)

    The number of bans to fetch.

  • before (Discorb::Snowflake) (defaults to: nil)

    The ID of the ban to fetch before.

  • after (Discorb::Snowflake) (defaults to: nil)

    The ID of the ban to fetch after.

  • around (Discorb::Snowflake) (defaults to: nil)

    The ID of the ban to fetch around.

Returns:



1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'lib/discorb/guild.rb', line 1036

def fetch_bans(limit = 50, before: nil, after: nil, around: nil)
  Async do
    params =
      {
        limit: limit,
        before: Discorb::Utils.try(after, :id),
        after: Discorb::Utils.try(around, :id),
        around: Discorb::Utils.try(before, :id)
      }.filter { |_k, v| !v.nil? }.to_h
    _resp, bans =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/bans?#{URI.encode_www_form(params)}",
            "//guilds/:guild_id/bans",
            :get
          )
        )
        .wait
    bans.map { |d| Ban.new(@client, self, d) }
  end
end

#fetch_channelsAsync::Task<Array<Discorb::Channel>>

Fetch channels of the guild.

Returns:



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/discorb/guild.rb', line 499

def fetch_channels
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/channels",
            "//guilds/:guild_id/channels",
            :get
          )
        )
        .wait
    data.map { |c| Channel.make_channel(@client, c) }
  end
end

#fetch_emoji(id) ⇒ Async::Task<Discorb::CustomEmoji>

Note:

This querys the API every time. We recommend using #emojis instead.

Fetch emoji id of the guild.

Parameters:

  • id (#to_s)

    The emoji id.

Returns:



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/discorb/guild.rb', line 398

def fetch_emoji(id)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/emojis/#{id}",
            "//guilds/:guild_id/emojis/:emoji_id",
            :get
          )
        )
        .wait
    @emojis[e[:id]] = CustomEmoji.new(@client, self, data)
  end
end

#fetch_emoji_listAsync::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}> Also known as: fetch_emojis

Note:

This querys the API every time. We recommend using #emojis instead.

Fetch emoji list of the guild.

Returns:



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/discorb/guild.rb', line 363

def fetch_emoji_list
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/emojis",
            "//guilds/:guild_id/emojis",
            :get
          )
        )
        .wait
    @emojis = Dictionary.new
    ids = @emojis.map(&:id).map(&:to_s)
    data.map do |e|
      next if ids.include?(e[:id])

      @emojis[e[:id]] = CustomEmoji.new(@client, self, e)
    end
    @emojis
  end
end

#fetch_integrationsAsync::Task<Array<Discorb::Integration>>

Fetch integrations in the guild.

Returns:



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
# File 'lib/discorb/guild.rb', line 1333

def fetch_integrations
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/integrations",
            "//guilds/:guild_id/integrations",
            :get
          )
        )
        .wait
    data.map { |d| Integration.new(@client, d, @id) }
  end
end

#fetch_invitesAsync::Task<Array<Invite>>

Fetch invites in the guild.

Returns:

  • (Async::Task<Array<Invite>>)

    The invites.



1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'lib/discorb/guild.rb', line 1310

def fetch_invites
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/invites",
            "//guilds/:guild_id/invites",
            :get
          )
        )
        .wait
    data.map { |d| Invite.new(@client, d, false) }
  end
end

#fetch_member(id) ⇒ Async::Task<Discorb::Member>, Async::Task<nil>

Fetch a member in the guild.

Parameters:

  • id (#to_s)

    The ID of the member to fetch.

Returns:

  • (Async::Task<Discorb::Member>)

    The member.

  • (Async::Task<nil>)

    If the member is not found.



858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/discorb/guild.rb', line 858

def fetch_member(id)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/members/#{id}",
            "//guilds/:guild_id/members/:user_id",
            :get
          )
        )
        .wait
  rescue Discorb::NotFoundError
    nil
  else
    Member.new(@client, @id, data[:user], data)
  end
end

#fetch_member_namedAsync::Task<Discorb::Member>, Async::Task<nil>

Almost the same as #fetch_members_named, but returns a single member.

Returns:

  • (Async::Task<Discorb::Member>)

    The member.

  • (Async::Task<nil>)

    If the member is not found.



965
966
967
# File 'lib/discorb/guild.rb', line 965

def fetch_member_named(...)
  Async { fetch_members_named(...).first }
end

#fetch_members(limit: 0, after: nil) ⇒ Async::Task<Array<Discorb::Member>> Also known as: fetch_member_list

Note:

You must enable GUILD_MEMBERS intent to use this method.

Fetch members in the guild.

Parameters:

  • limit (Integer) (defaults to: 0)

    The maximum number of members to fetch, 0 for all.

  • after (Integer) (defaults to: nil)

    The ID of the member to start fetching after.

Returns:



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'lib/discorb/guild.rb', line 887

def fetch_members(limit: 0, after: nil)
  Async do
    unless limit.zero?
      _resp, data =
        @client
          .http
          .request(
            Route.new(
              "/guilds/#{@id}/members?#{
                URI.encode_www_form({ after: after, limit: limit })
              }",
              "//guilds/:guild_id/members",
              :get
            )
          )
          .wait
      next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
    end
    ret = []
    after = 0
    loop do
      params = { after: after, limit: 100 }
      _resp, data =
        @client
          .http
          .request(
            Route.new(
              "/guilds/#{@id}/members?#{URI.encode_www_form(params)}",
              "//guilds/:guild_id/members",
              :get
            )
          )
          .wait
      ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
      after = data.last[:user][:id]
      break if data.length != 100
    end
    ret
  end
end

#fetch_members_named(name, limit: 1) ⇒ Async::Task<Array<Discorb::Member>>

Search for members by name in the guild.

Parameters:

  • name (String)

    The name of the member to search for.

  • limit (Integer) (defaults to: 1)

    The maximum number of members to return.

Returns:



939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'lib/discorb/guild.rb', line 939

def fetch_members_named(name, limit: 1)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/members/search?#{
              URI.encode_www_form({ query: name, limit: limit })
            }",
            "//guilds/:guild_id/members/search",
            :get
          )
        )
        .wait
    data.map { |d| Member.new(@client, @id, d[:user], d) }
  end
end

#fetch_prune(days = 7, roles: []) ⇒ Async::Task<Integer>

Fetch how many members will be pruned.

Parameters:

  • days (Integer) (defaults to: 7)

    The number of days to prune.

  • roles (Array<Discorb::Role>) (defaults to: [])

    The roles that include for pruning.

Returns:

  • (Async::Task<Integer>)

    The number of members that will be pruned.



1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/discorb/guild.rb', line 1230

def fetch_prune(days = 7, roles: [])
  Async do
    params = { days: days, include_roles: @id.to_s }
    param[:include_roles] = roles
      .map(&:id)
      .map(&:to_s)
      .join(";") if roles.any?
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/prune?#{URI.encode_www_form(params)}",
            "//guilds/:guild_id/prune",
            :get
          )
        )
        .wait
    data[:pruned]
  end
end

#fetch_rolesAsync::Task<Array<Discorb::Role>>

Fetch a list of roles in the guild.

Returns:



1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
# File 'lib/discorb/guild.rb', line 1162

def fetch_roles
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/roles",
            "//guilds/:guild_id/roles",
            :get
          )
        )
        .wait
    data.map { |d| Role.new(@client, self, d) }
  end
end

#fetch_scheduled_event(id) ⇒ Async::Task<Discorb::ScheduledEvent>, Async::Task<nil>

Fetch the scheduled event by ID.

Parameters:

  • id (#to_s)

    The ID of the scheduled event.

Returns:

  • (Async::Task<Discorb::ScheduledEvent>)

    The event with the given ID.

  • (Async::Task<nil>)

    If no event with the given ID exists.



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/discorb/guild.rb', line 237

def fetch_scheduled_event(id)
  Async do
    _resp, event =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/scheduled-events/#{id}",
            "//guilds/:guild_id/scheduled-events/:scheduled_event_id",
            :get
          )
        )
        .wait
    ScheduledEvent.new(@client, event)
  end
end

#fetch_scheduled_events(with_user_count: true) ⇒ Array<Discorb::ScheduledEvent>

Fetch scheduled events for the guild.

Parameters:

  • with_user_count (Boolean) (defaults to: true)

    Whether to include the user count in the events. Defaults to true.

Returns:



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/discorb/guild.rb', line 211

def fetch_scheduled_events(with_user_count: true)
  Async do
    _resp, events =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/scheduled-events?with_user_count=#{with_user_count}",
            "//guilds/:guild_id/scheduled-events",
            :get
          )
        )
        .wait
    @scheduled_events = events.map { |e| ScheduledEvent.new(@client, e) }
  end
end

#fetch_sticker(id) ⇒ Async::Task<Discorb::Sticker::GuildSticker>, Async::Task<nil>

Fetch the sticker by ID.

Parameters:

  • id (#to_s)

    The ID of the sticker.

Returns:



1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/discorb/guild.rb', line 1451

def fetch_sticker(id)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/stickers/#{id}",
            "//guilds/:guild_id/stickers/:sticker_id",
            :get
          )
        )
        .wait
  rescue Discorb::NotFoundError
    nil
  else
    Sticker::GuildSticker.new(@client, data)
  end
end

#fetch_stickersAsync::Task<Array<Discorb::Sticker::GuildSticker>>

Fetch stickers in the guild.

Returns:



1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
# File 'lib/discorb/guild.rb', line 1425

def fetch_stickers
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/stickers",
            "//guilds/:guild_id/stickers",
            :get
          )
        )
        .wait
    data.map { |d| Sticker::GuildSticker.new(@client, d) }
  end
end

#fetch_templateDiscorb::GuildTemplate, Async::Task<nil>

Almost the same as #fetch_templates, but returns a single template.

Returns:



1500
1501
1502
# File 'lib/discorb/guild.rb', line 1500

def fetch_template
  Async { fetch_templates.wait.first }
end

#fetch_templatesAsync::Task<Discorb::GuildTemplate>

Fetch templates in the guild.

Returns:



1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
# File 'lib/discorb/guild.rb', line 1477

def fetch_templates
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/templates",
            "//guilds/:guild_id/templates",
            :get
          )
        )
        .wait
    data.map { |d| GuildTemplate.new(@client, d) }
  end
end

#fetch_vanity_inviteAsync::Task<Discorb::Guild::VanityInvite>

Fetch the vanity URL of the guild.

Returns:



1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
# File 'lib/discorb/guild.rb', line 1379

def fetch_vanity_invite
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/vanity-url",
            "//guilds/:guild_id/vanity-url",
            :get
          )
        )
        .wait
    VanityInvite.new(@client, self, data)
  end
end

#fetch_voice_regionsAsync::Task<Array<Discorb::VoiceRegion>>

Fetch voice regions that are available in the guild.

Returns:



1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
# File 'lib/discorb/guild.rb', line 1287

def fetch_voice_regions
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/voice",
            "//guilds/:guild_id/voice",
            :get
          )
        )
        .wait
    data.map { |d| VoiceRegion.new(d) }
  end
end

#fetch_webhooksAsync::Task<Array<Discorb::Webhook>>

Fetch webhooks of the guild.

Returns:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/discorb/guild.rb', line 453

def fetch_webhooks
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/webhooks",
            "//guilds/:guild_id/webhooks",
            :get
          )
        )
        .wait
    data.map { |webhook| Webhook.from_data(@client, webhook) }
  end
end

#fetch_welcome_screenAsync::Task<Discorb::WelcomeScreen>

Fetch the welcome screen of the guild.

Returns:



1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
# File 'lib/discorb/guild.rb', line 1402

def fetch_welcome_screen
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/welcome-screen",
            "//guilds/:guild_id/welcome-screen",
            :get
          )
        )
        .wait
    WelcomeScreen.new(@client, self, data)
  end
end

#fetch_widgetAsync::Task<Discorb::Guild::Widget>

Fetch the widget of the guild.

Returns:



1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
# File 'lib/discorb/guild.rb', line 1356

def fetch_widget
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/widget",
            "//guilds/:guild_id/widget",
            :get
          )
        )
        .wait
    Widget.new(@client, @id, data)
  end
end

#inspectObject



172
173
174
# File 'lib/discorb/guild.rb', line 172

def inspect
  "#<#{self.class} \"#{@name}\" id=#{@id}>"
end

#kick_member(member, reason: nil) ⇒ Async::Task<void>

Kick a member from the guild.

Parameters:

  • member (Discorb::Member)

    The member to kick.

  • reason (String) (defaults to: nil)

    The reason for kicking the member.

Returns:

  • (Async::Task<void>)

    The task.



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'lib/discorb/guild.rb', line 1008

def kick_member(member, reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@id}/members/#{member.id}",
          "//guilds/:guild_id/members/:user_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
  end
end

#leaveAsync::Task<void>

Leave the guild.

Returns:

  • (Async::Task<void>)

    The task.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/discorb/guild.rb', line 186

def leave
  Async do
    @client
      .http
      .request(
        Route.new(
          "/users/@me/guilds/#{@id}",
          "//users/@me/guilds/:guild_id",
          :delete
        )
      )
      .wait
    @client.guilds.delete(@id)
  end
end

#prune(days = 7, roles: [], reason: nil) ⇒ Async::Task<Integer>

Prune members from the guild.

Parameters:

  • days (Integer) (defaults to: 7)

    The number of days to prune.

  • roles (Array<Discorb::Role>) (defaults to: [])

    The roles that include for pruning.

  • reason (String) (defaults to: nil)

    The reason for pruning.

Returns:

  • (Async::Task<Integer>)

    The number of members that were pruned.



1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
# File 'lib/discorb/guild.rb', line 1262

def prune(days = 7, roles: [], reason: nil)
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@id}/prune",
            "//guilds/:guild_id/prune",
            :post
          ),
          { days: days, roles: roles.map(&:id) },
          audit_log_reason: reason
        )
        .wait
    data[:pruned]
  end
end

#unban_user(user, reason: nil) ⇒ Async::Task<void>

Unban a user from the guild.

Parameters:

  • user (Discorb::User)

    The user to unban.

  • reason (String) (defaults to: nil)

    The reason for unbanning the user.

Returns:

  • (Async::Task<void>)

    The task.



1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File 'lib/discorb/guild.rb', line 1139

def unban_user(user, reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@id}/bans/#{user.id}",
          "//guilds/:guild_id/bans/:user_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
  end
end