class Discorb::Guild
Represents a guild in the Discord.
Attributes
@!visibility private
@!visibility private
@!visibility private
@!visibility private
@!visibility private
@return [Integer] The AFK timeout of the guild.
@return [Integer] The approxmate amount of members in the guild.
@return [Integer] The approxmate amount of non-offline members in the guild.
@return [Boolean] Whether the guild is available.
@return [Boolean] Whether the guild is available.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.
@return [:all_messages, :only_mentions] The default message notification level of the guild.
@return [String] The description of the guild.
@return [Discorb::Asset] The discovery splash of the guild.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}] A dictionary of custom emojis in the guild.
@return [:disabled_in_text, :members_without_roles, :all_members] The explict content filter level of the guild.
@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
@return [Discorb::Asset] The icon of the guild.
@return [Discorb::Snowflake] ID of the guild.
@return [Time] Time
that representing when bot has joined the guild.
@return [Boolean] Whether the guild is large.
@return [Boolean] Whether the guild is large.
@return [Integer] Number of online members in the guild.
@return [Integer] The maximum amount of users in a video channel.
@return [Integer] The amount of members in the guild.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Member}] A dictionary of members in the guild. @macro members_intent
@return [:none, :elevated] The MFA level of the guild.
@return [String] The name of the guild.
@return [:default, :explicit, :safe, :age_restricted] The nsfw level of the guild.
@return [Boolean] Whether the client is the owner of the guild.
@return [Boolean] Whether the client is the owner of the guild.
@return [Discorb::Snowflake] ID of the guild owner.
@return [Discorb::Permission] The bot's permission in the guild.
@return [Symbol] The preffered language of the guild. @note This modifies the language code, `-` will be replaced with `_`.
@return [Discorb::Dictionary{Discorb::User => Discorb::Presence}] A dictionary of presence in the guild.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.
@return [Discorb::Asset] The splash of the guild.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}] A dictionary of stage instances in the guild.
@return [Discorb::Guild::SystemChannelFlag] The flag for the system channel.
@return [Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel}] A dictionary of threads in the guild.
@return [String] The vanity invite URL for the guild. @return [nil] If the guild does not have a vanity invite URL.
@return [:none, :low, :medium, :high, :very_high] The verification level of the guild.
@return [Discorb::Dictionary{Discorb::User => Discorb::VoiceState}] A dictionary of voice states in the guild.
@return [Discorb::WelcomeScreen] The welcome screen of the guild.
@return [Boolean] Whether the guild enabled the widget.
@return [Boolean] Whether the guild enabled the widget.
Public Class Methods
@!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
# File lib/discorb/guild.rb, line 136 def afk_channel @client.channels[@afk_channel_id] end
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
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 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
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 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 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 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 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 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 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
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
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 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 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 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 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 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 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
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 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 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
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
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 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 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 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 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
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 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 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 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 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 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 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
# File lib/discorb/guild.rb, line 152 def inspect "#<#{self.class} \"#{@name}\" id=#{@id}>" end
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 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
# File lib/discorb/guild.rb, line 156 def me @members[@client.user.id] end
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
# File lib/discorb/guild.rb, line 148 def public_updates_channel @client.channels[@public_updates_channel_id] end
# File lib/discorb/guild.rb, line 144 def rules_channel @client.channels[@rules_channel_id] end
# File lib/discorb/guild.rb, line 140 def system_channel @client.channels[@system_channel_id] end
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
@!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
# 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