class Discorb::Guild

Represents a guild in the Discord.

Attributes

default_message_notifications[R]

@!visibility private

explicit_content_filter[R]

@!visibility private

mfa_levels[R]

@!visibility private

nsfw_levels[R]

@!visibility private

verification_levels[R]

@!visibility private

afk_timeout[R]

@return [Integer] The AFK timeout of the guild.

approximate_member_count[R]

@return [Integer] The approxmate amount of members in the guild.

approximate_presence_count[R]

@return [Integer] The approxmate amount of non-offline members in the guild.

available[R]

@return [Boolean] Whether the guild is available.

available?[R]

@return [Boolean] Whether the guild is available.

banner[R]

@return [Discorb::Asset] The banner of the guild. @return [nil] If the guild does not have a banner.

channels[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.

default_message_notifications[R]

@return [:all_messages, :only_mentions] The default message notification level of the guild.

description[R]

@return [String] The description of the guild.

discovery_splash[R]

@return [Discorb::Asset] The discovery splash of the guild.

emojis[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}] A dictionary of custom emojis in the guild.

explicit_content_filter[R]

@return [:disabled_in_text, :members_without_roles, :all_members] The explict content filter level of the guild.

features[R]

@return [Array<Symbol>] features that are enabled in the guild. @see discord.com/developers/docs/resources/guild#guild-object-guild-features Official Discord API docs

icon[R]

@return [Discorb::Asset] The icon of the guild.

id[R]

@return [Discorb::Snowflake] ID of the guild.

joined_at[R]

@return [Time] Time that representing when bot has joined the guild.

large[R]

@return [Boolean] Whether the guild is large.

large?[R]

@return [Boolean] Whether the guild is large.

max_presences[R]

@return [Integer] Number of online members in the guild.

max_video_channel_users[R]

@return [Integer] The maximum amount of users in a video channel.

member_count[R]

@return [Integer] The amount of members in the guild.

members[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Member}] A dictionary of members in the guild. @macro members_intent

mfa_level[R]

@return [:none, :elevated] The MFA level of the guild.

name[R]

@return [String] The name of the guild.

nsfw_level[R]

@return [:default, :explicit, :safe, :age_restricted] The nsfw level of the guild.

owner[R]

@return [Boolean] Whether the client is the owner of the guild.

owner?[R]

@return [Boolean] Whether the client is the owner of the guild.

owner_id[R]

@return [Discorb::Snowflake] ID of the guild owner.

permissions[R]

@return [Discorb::Permission] The bot's permission in the guild.

preferred_locale[R]

@return [Symbol] The preffered language of the guild. @note This modifies the language code, `-` will be replaced with `_`.

premium_subscription_count[R]

@return [Integer] The amount of premium subscriptions (Server Boosts) the guild has.

premium_tier[R]

@return [Integer] The premium tier (Boost Level) of the guild.

presences[R]

@return [Discorb::Dictionary{Discorb::User => Discorb::Presence}] A dictionary of presence in the guild.

roles[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.

splash[R]

@return [Discorb::Asset] The splash of the guild.

stage_instances[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}] A dictionary of stage instances in the guild.

system_channel_flags[R]

@return [Discorb::Guild::SystemChannelFlag] The flag for the system channel.

threads[R]

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel}] A dictionary of threads in the guild.

unavailable[R]

@return [Boolean] Whether the guild is unavailable.

vanity_url_code[R]

@return [String] The vanity invite URL for the guild. @return [nil] If the guild does not have a vanity invite URL.

verification_level[R]

@return [:none, :low, :medium, :high, :very_high] The verification level of the guild.

voice_states[R]

@return [Discorb::Dictionary{Discorb::User => Discorb::VoiceState}] A dictionary of voice states in the guild.

welcome_screen[R]

@return [Discorb::WelcomeScreen] The welcome screen of the guild.

widget_enabled[R]

@return [Boolean] Whether the guild enabled the widget.

widget_enabled?[R]

@return [Boolean] Whether the guild enabled the widget.

Public Class Methods

banner(guild_id, style: "banner") click to toggle source

Returns a banner url from the guild's ID.

@param [#to_s] guild_id The ID of the guild. @param [:shield, :banner1, :banner2, :banner3, :banner4] style The style of the banner.

@return [String] The url of the banner.

new(client, data, is_create_event) click to toggle source

@!visibility private

# File lib/discorb/guild.rb, line 122
def initialize(client, data, is_create_event)
  @client = client
  @data = {}
  _set_data(data, is_create_event)
end

Public Instance Methods

afk_channel() click to toggle source
# File lib/discorb/guild.rb, line 136
def afk_channel
  @client.channels[@afk_channel_id]
end
ban_member(member, delete_message_days: 0, reason: nil) click to toggle source

Ban a member from the guild. @macro async @macro http

@param [Discorb::Member] member The member to ban. @param [Integer] delete_message_days The number of days to delete messages. @param [String] reason The reason for banning the member.

@return [Discorb::Guild::Ban] The ban.

# File lib/discorb/guild.rb, line 643
def ban_member(member, delete_message_days: 0, reason: nil)
  Async do
    _resp, data = @client.http.post(
      "/guilds/#{@id}/bans", { user: member.id, delete_message_days: delete_message_days }, audit_log_reason: reason,
    ).wait
    Ban.new(@client, self, data)
  end
end
banned?(user) click to toggle source

Checks the user was banned from the guild. @macro async @macro http

@param [Discorb::User] user The user to check.

@return [Boolean] Whether the user was banned.

# File lib/discorb/guild.rb, line 626
def banned?(user)
  Async do
    !fetch_ban(user).wait.nil?
  end
end
create_category(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil)
create_category_channel(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil) click to toggle source

Create a new category channel. @macro async @macro http

@param [String] name The name of the channel. @param [Integer] position The position of the channel. @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites. @param [Discorb::CategoryChannel] parent The parent of the channel. @param [String] reason The reason for creating the channel.

@return [Discorb::CategoryChannel] The created category channel.

# File lib/discorb/guild.rb, line 378
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.post(
      "/guilds/#{@id}/channels", payload, audit_log_reason: reason,
    ).wait
    Channel.make_channel(@client, data)
  end
end
Also aliased as: create_category
create_emoji(name, image, roles: []) click to toggle source

Create a custom emoji. @macro async @macro http

@param [#to_s] name The name of the emoji. @param [Discorb::Image] image The image of the emoji. @param [Array<Discorb::Role>] roles A list of roles to give the emoji.

@return [Discorb::CustomEmoji] The created emoji.

# File lib/discorb/guild.rb, line 222
def create_emoji(name, image, roles: [])
  _resp, data = @client.http.post(
    "/guilds/#{@id}/emojis",
    {
      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
create_news_channel( name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil ) click to toggle source

Create a new news channel. @macro async @macro http

@param [String] name The name of the channel. @param [String] topic The topic of the channel. @param [Integer] rate_limit_per_user The rate limit per user in the channel. @param [Integer] slowmode Alias for `rate_limit_per_user`. @param [Integer] position The position of the channel. @param [Boolean] nsfw Whether the channel is nsfw. @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites. @param [Discorb::CategoryChannel] parent The parent of the channel. @param [String] reason The reason for creating the channel.

@return [Discorb::NewsChannel] The created news channel.

# File lib/discorb/guild.rb, line 458
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.post(
      "/guilds/#{@id}/channels", 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) click to toggle source

Create a role in the guild. @macro async @macro http

@param [String] name The name of the role. @param [Discorb::Color] color The color of the role. @param [Boolean] hoist Whether the role should be hoisted. @param [Boolean] mentionable Whether the role should be mentionable. @param [String] reason The reason for creating the role.

@return [Discorb::Role] The role.

# File lib/discorb/guild.rb, line 693
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.post(
      "/guilds/#{@id}/roles", payload, audit_log_reason: reason,
    ).wait
    Role.new(@client, self, data)
  end
end
create_stage_channel(name, bitrate: 64, position: nil, permission_overwrites: nil, parent: nil, reason: nil) click to toggle source

Create a new stage channel. @macro async @macro http

@param [String] name The name of the channel. @param [Integer] bitrate The bitrate of the channel. @param [Integer] position The position of the channel. @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites. @param [Discorb::CategoryChannel] parent The parent of the channel. @param [String] reason The reason for creating the channel.

@return [Discorb::StageChannel] The created stage channel.

# File lib/discorb/guild.rb, line 417
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.post(
      "/guilds/#{@id}/channels", payload, audit_log_reason: reason,
    ).wait
    Channel.make_channel(@client, data)
  end
end
create_template(name, description = nil, reason: nil) click to toggle source

Create a new template in the guild.

@param [String] name The name of the template. @param [String] description The description of the template. @param [String] reason The reason for creating the template.

@return [Discorb::GuildTemplate] The template.

# File lib/discorb/guild.rb, line 902
def create_template(name, description = nil, reason: nil)
  Async do
    _resp, data = @client.http.post(
      "/guilds/#{@id}/templates", { 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 ) click to toggle source

Create a new text channel. @macro async @macro http

@param [String] name The name of the channel. @param [String] topic The topic of the channel. @param [Integer] rate_limit_per_user The rate limit per user in the channel. @param [Integer] slowmode Alias for `rate_limit_per_user`. @param [Integer] position The position of the channel. @param [Boolean] nsfw Whether the channel is nsfw. @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites. @param [Discorb::CategoryChannel] parent The parent of the channel. @param [String] reason The reason for creating the channel.

@return [Discorb::TextChannel] The created text channel.

# File lib/discorb/guild.rb, line 293
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.post(
      "/guilds/#{@id}/channels", 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 ) click to toggle source

Create a new voice channel. @macro async @macro http

@param [String] name The name of the channel. @param [Integer] bitrate The bitrate of the channel. @param [Integer] user_limit The user limit of the channel. @param [Integer] position The position of the channel. @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites. @param [Discorb::CategoryChannel] parent The parent of the channel. @param [String] reason The reason for creating the channel.

@return [Discorb::VoiceChannel] The created voice channel.

# File lib/discorb/guild.rb, line 338
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.post(
      "/guilds/#{@id}/channels", payload, audit_log_reason: reason,
    ).wait
    payload[:parent_id] = parent&.id
    Channel.make_channel(@client, data)
  end
end
edit_nick(nickname, reason: nil)
Alias for: edit_nickname
edit_nickname(nickname, reason: nil) click to toggle source

Change nickname of client member.

@param [String] nickname The nickname to set. @param [String] reason The reason for changing the nickname.

# File lib/discorb/guild.rb, line 559
def edit_nickname(nickname, reason: nil)
  Async do
    @client.http.patch("/guilds/#{@id}/members/@me/nick", { nick: nickname }, audit_log_reason: reason).wait
  end
end
Also aliased as: edit_nick, modify_nickname
fetch_active_threads() click to toggle source

Fetch a list of active threads in the guild. @macro async @macro http

@return [Array<Discorb::ThreadChannel>] The list of threads.

# File lib/discorb/guild.rb, line 494
def fetch_active_threads
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/threads/active").wait
    data[:threads].map { |t| Channel.make_thread(@client, t) }
  end
end
fetch_audit_log() click to toggle source

Fetch audit log of the guild. @macro async @macro http

@return [Discorb::AuditLog] The audit log of the guild.

# File lib/discorb/guild.rb, line 255
def fetch_audit_log
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/audit-logs").wait
    AuditLog.new(@client, data, self)
  end
end
fetch_ban(user) click to toggle source

Fetch a ban in the guild. @macro async @macro http

@param [Discorb::User] user The user to fetch.

@return [Discorb::Guild::Ban] The ban. @return [nil] If the ban is not found.

# File lib/discorb/guild.rb, line 607
def fetch_ban(user)
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/bans/#{user.id}").wait
  rescue Discorb::NotFoundError
    nil
  else
    Ban.new(@client, self, data)
  end
end
fetch_bans() click to toggle source

Fetch a list of bans in the guild. @macro async @macro http

@return [Array<Discorb::Guild::Ban>] The list of bans.

# File lib/discorb/guild.rb, line 590
def fetch_bans
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/bans").wait
    data.map { |d| Ban.new(@client, self, d) }
  end
end
fetch_channels() click to toggle source

Fetch channels of the guild. @macro async @macro http

@return [Array<Discorb::Channel>] A list of channels in the guild.

# File lib/discorb/guild.rb, line 269
def fetch_channels
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/channels").wait
    data.map { |c| Channel.make_channel(@client, c) }
  end
end
fetch_emoji(id) click to toggle source

Fetch emoji id of the guild. @macro async @macro http @note This querys the API every time. We recommend using {#emojis} instead.

@param [#to_s] id The emoji id.

@return [Discorb::CustomEmoji] The emoji with the given id.

# File lib/discorb/guild.rb, line 206
def fetch_emoji(id)
  _resp, data = @client.http.get("/guilds/#{@id}/emojis/#{id}").wait
  @emojis[e[:id]] = CustomEmoji.new(@client, self, data)
end
fetch_emoji_list() click to toggle source

Fetch emoji list of the guild. @macro async @macro http @note This querys the API every time. We recommend using {#emojis} instead.

@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}] A dictionary of emoji in the guild.

# File lib/discorb/guild.rb, line 180
def fetch_emoji_list
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/emojis").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
Also aliased as: fetch_emojis
fetch_emojis()
Alias for: fetch_emoji_list
fetch_integrations() click to toggle source

Fetch integrations in the guild. @macro async @macro http

@return [Array<Discorb::Integration>] The integrations.

# File lib/discorb/guild.rb, line 784
def fetch_integrations
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/integrations").wait
    data.map { |d| Integration.new(@client, d) }
  end
end
fetch_invites() click to toggle source

Fetch invites in the guild. @macro async @macro http

@return [Array<Invite>] The invites.

# File lib/discorb/guild.rb, line 770
def fetch_invites
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/invites").wait
    data.map { |d| Invite.new(@client, d) }
  end
end
fetch_member(id) click to toggle source

Fetch a member in the guild. @macro async @macro http @macro members_intent

@param [#to_s] id The ID of the member to fetch.

@return [Discorb::Member] The member. @return [nil] If the member is not found.

# File lib/discorb/guild.rb, line 512
def fetch_member(id)
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/members/#{id}").wait
  rescue Discorb::NotFoundError
    nil
  else
    Member.new(@client, @id, data[:user], data)
  end
end
fetch_member_named(...) click to toggle source

Almost the same as {#fetch_members_named}, but returns a single member. @macro async @macro http

@return [Discorb::Member] The member. @return [nil] If the member is not found.

# File lib/discorb/guild.rb, line 547
def fetch_member_named(...)
  Async do
    fetch_members_named(...).first
  end
end
fetch_members_named(name, limit: 1) click to toggle source

Search for members by name in the guild. @macro async @macro http

@param [String] name The name of the member to search for. @param [Integer] limit The maximum number of members to return.

@return [Array<Discorb::Member>] The list of members.

# File lib/discorb/guild.rb, line 532
def fetch_members_named(name, limit: 1)
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/members/search?#{URI.encode_www_form({ query: name, limit: limit })}").wait
    data.map { |d| Member.new(@client, @id, d[:user], d) }
  end
end
fetch_prune(days = 7, roles: []) click to toggle source

Fetch how many members will be pruned. @macro async @macro http

@param [Integer] days The number of days to prune. @param [Array<Discorb::Role>] roles The roles that include for pruning.

@return [Integer] The number of members that will be pruned.

# File lib/discorb/guild.rb, line 717
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.get("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}").wait
    data[:pruned]
  end
end
fetch_roles() click to toggle source

Fetch a list of roles in the guild. @macro async @macro http

@return [Array<Discorb::Role>] The list of roles.

# File lib/discorb/guild.rb, line 673
def fetch_roles
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/roles").wait
    data.map { |d| Role.new(@client, self, d) }
  end
end
fetch_sticker(id) click to toggle source

Fetch the sticker by ID. @macro async @macro http

@param [#to_s] id The ID of the sticker.

@return [Discorb::Sticker::GuildSticker] The sticker. @return [nil] If the sticker does not exist.

# File lib/discorb/guild.rb, line 857
def fetch_sticker(id)
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/stickers/#{id}").wait
  rescue Discorb::NotFoundError
    nil
  else
    Sticker::GuildSticker.new(@client, data)
  end
end
fetch_stickers() click to toggle source

Fetch stickers in the guild. @macro async @macro http

@return [Array<Discorb::Sticker::GuildSticker>] The stickers.

# File lib/discorb/guild.rb, line 840
def fetch_stickers
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/stickers").wait
    data.map { |d| Sticker::GuildSticker.new(@client, d) }
  end
end
fetch_template() click to toggle source

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

@return [Discorb::GuildTemplate] The template. @return [nil] If the template does not exist.

# File lib/discorb/guild.rb, line 887
def fetch_template
  Async do
    fetch_templates.wait.first
  end
end
fetch_templates() click to toggle source

Fetch templates in the guild. @macro async @macro http

@return [Discorb::GuildTemplate] The templates.

# File lib/discorb/guild.rb, line 874
def fetch_templates
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/templates").wait
    data.map { |d| GuildTemplate.new(@client, d) }
  end
end
fetch_vanity_invite() click to toggle source

Fetch the vanity URL of the guild. @macro async @macro http

@return [Discorb::Guild::VanityInvite] The vanity URL.

# File lib/discorb/guild.rb, line 812
def fetch_vanity_invite
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/vanity-url").wait
    VanityInvite.new(@client, self, data)
  end
end
fetch_voice_regions() click to toggle source

Fetch voice regions that are available in the guild. @macro async @macro http

@return [Array<Discorb::VoiceRegion>] The available voice regions.

# File lib/discorb/guild.rb, line 756
def fetch_voice_regions
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/voice").wait
    data.map { |d| VoiceRegion.new(@client, d) }
  end
end
fetch_webhooks() click to toggle source

Fetch webhooks of the guild. @macro async @macro http

@return [Array<Discorb::Webhook>] A list of webhooks in the guild.

# File lib/discorb/guild.rb, line 241
def fetch_webhooks
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/webhooks").wait
    data.map { |webhook| Webhook.new([@client, webhook]) }
  end
end
fetch_welcome_screen() click to toggle source

Fetch the welcome screen of the guild. @macro async @macro http

@return [Discorb::Guild::WelcomeScreen] The welcome screen.

# File lib/discorb/guild.rb, line 826
def fetch_welcome_screen
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/welcome-screen").wait
    WelcomeScreen.new(@client, self, data)
  end
end
fetch_widget() click to toggle source

Fetch the widget of the guild. @macro async @macro http

@return [Discorb::Guild::Widget] The widget.

# File lib/discorb/guild.rb, line 798
def fetch_widget
  Async do
    _resp, data = @client.http.get("/guilds/#{@id}/widget").wait
    Widget.new(@client, @id, data)
  end
end
inspect() click to toggle source
# File lib/discorb/guild.rb, line 152
def inspect
  "#<#{self.class} \"#{@name}\" id=#{@id}>"
end
kick_member(member, reason: nil) click to toggle source

Kick a member from the guild. @macro async @macro http

@param [Discorb::Member] member The member to kick. @param [String] reason The reason for kicking the member.

# File lib/discorb/guild.rb, line 577
def kick_member(member, reason: nil)
  Async do
    @client.http.delete("/guilds/#{@id}/members/#{member.id}", audit_log_reason: reason).wait
  end
end
leave!() click to toggle source

Leave the guild. @macro async @macro http

# File lib/discorb/guild.rb, line 165
def leave!
  Async do
    @client.http.delete("/users/@me/guilds/#{@id}").wait
    @client.guilds.delete(@id)
  end
end
me() click to toggle source
# File lib/discorb/guild.rb, line 156
def me
  @members[@client.user.id]
end
modify_nick(nickname, reason: nil)
Alias for: modify_nickname
modify_nickname(nickname, reason: nil)
Also aliased as: modify_nick
Alias for: edit_nickname
prune(days = 7, roles: [], reason: nil) click to toggle source

Prune members from the guild. @macro async @macro http

@param [Integer] days The number of days to prune. @param [Array<Discorb::Role>] roles The roles that include for pruning. @param [String] reason The reason for pruning.

@return [Integer] The number of members that were pruned.

# File lib/discorb/guild.rb, line 740
def prune(days = 7, roles: [], reason: nil)
  Async do
    _resp, data = @client.http.post(
      "/guilds/#{@id}/prune", { days: days, roles: roles.map(&:id) }, audit_log_reason: reason,
    ).wait
    data[:pruned]
  end
end
public_updates_channel() click to toggle source
# File lib/discorb/guild.rb, line 148
def public_updates_channel
  @client.channels[@public_updates_channel_id]
end
rules_channel() click to toggle source
# File lib/discorb/guild.rb, line 144
def rules_channel
  @client.channels[@rules_channel_id]
end
system_channel() click to toggle source
# File lib/discorb/guild.rb, line 140
def system_channel
  @client.channels[@system_channel_id]
end
unban_user(user, reason: nil) click to toggle source

Unban a user from the guild. @macro async @macro http

@param [Discorb::User] user The user to unban. @param [String] reason The reason for unbanning the user.

# File lib/discorb/guild.rb, line 660
def unban_user(user, reason: nil)
  Async do
    @client.http.delete("/guilds/#{@id}/bans/#{user.id}", audit_log_reason: reason).wait
  end
end
update!() click to toggle source

@!visibility private

# File lib/discorb/guild.rb, line 129
def update!
  Async do
    _, data = @client.get("/guilds/#{@id}").wait
    _set_data(data, false)
  end
end

Private Instance Methods

_set_data(data, is_create_event) click to toggle source
# File lib/discorb/guild.rb, line 1049
def _set_data(data, is_create_event)
  @id = Snowflake.new(data[:id])
  if data[:unavailable]
    @unavailable = true
    return
  end
  @client.guilds[@id] = self unless data[:no_cache]
  @icon = data[:icon] && Asset.new(self, data[:icon])
  @unavailable = false
  @name = data[:name]
  @members = Discorb::Dictionary.new
  data[:members].each do |m|
    Member.new(@client, @id, m[:user], m)
  end if data[:members]
  @splash = data[:splash] && Asset.new(self, data[:splash], path: "splashes/#{@id}")
  @discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash], path: "discovery-splashes/#{@id}")
  @owner_id = data[:owner_id]
  @permissions = Permission.new(data[:permissions].to_i)
  @afk_channel_id = data[:afk_channel_id]
  @afk_timeout = data[:afk_timeout]
  @widget_enabled = data[:widget_enabled]
  @widget_channel_id = data[:widget_channel_id]
  @roles = Dictionary.new
  data[:roles].each do |r|
    @roles[r[:id]] = Role.new(@client, self, r)
  end
  @emojis = Dictionary.new
  data[:emojis].map do |e|
    @emojis[e[:id]] = CustomEmoji.new(@client, self, e)
  end
  @features = data[:features].map { |f| f.downcase.to_sym }
  @mfa_level = self.class.mfa_levels[data[:mfa_level]]
  @verification_level = self.class.verification_levels[data[:verification_level]]
  @default_message_notifications = self.class.default_message_notifications[data[:default_message_notifications]]
  @explicit_content_filter = self.class.explicit_content_filter[data[:explicit_content_filter]]
  @system_channel_id = data[:system_channel_id]
  @system_channel_flag = SystemChannelFlag.new(0b111 - data[:system_channel_flags])
  @rules_channel_id = data[:rules_channel_id]
  @vanity_url_code = data[:vanity_url_code]
  @description = data[:description]
  @banner = data[:banner] && Asset.new(self, data[:banner], path: "banners/#{@id}")
  @premium_tier = data[:premium_tier]
  @premium_subscription_count = data[:premium_tier_count].to_i
  @preferred_locale = data[:preferred_locale].gsub("-", "_").to_sym
  @public_updates_channel_id = data[:public_updates_channel_id]
  @max_video_channel_users = data[:max_video_channel_users]
  @approximate_member_count = data[:approximate_member_count]
  @approximate_presence_count = data[:approximate_presence_count]
  @welcome_screen = data[:welcome_screen].nil? ? nil : WelcomeScreen.new(@client, self, data[:welcome_screen])
  @nsfw_level = self.class.nsfw_levels[data[:nsfw_level]]
  return unless is_create_event

  @stickers = data[:stickers].nil? ? [] : data[:stickers].map { |s| Sticker::GuildSticker.new(self, s) }
  @joined_at = Time.iso8601(data[:joined_at])
  @large = data[:large]
  @member_count = data[:member_count]
  tmp_channels = data[:channels].filter { |c| !c.key?(:thread_metadata) }.map do |c|
    Channel.make_channel(@client, c.merge({ guild_id: @id }))
  end
  @channels = Dictionary.new(tmp_channels.map { |c| [c.id, c] }.to_h, sort: ->(c) { c[1].position })
  @voice_states = Dictionary.new(data[:voice_states].map { |v| [Snowflake.new(v[:user_id]), VoiceState.new(@client, v.merge({ guild_id: @id }))] }.to_h)
  @threads = data[:threads] ? data[:threads].map { |t| Channel.make_channel(@client, t) } : []
  @presences = Dictionary.new(data[:presences].map { |pr| [Snowflake.new(pr[:user][:id]), Presence.new(@client, pr)] }.to_h)
  @max_presences = data[:max_presences]
  @stage_instances = Dictionary.new(data[:stage_instances].map { |s| [Snowflake.new(s[:id]), StageInstance.new(@client, s)] }.to_h)
  @data.update(data)
end