Class: Discorb::Guild
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::Guild
- Defined in:
- lib/discorb/guild.rb
Overview
Represents a guild in the Discord.
Defined Under Namespace
Classes: Ban, VanityInvite, Widget
Instance Attribute Summary collapse
-
#afk_timeout -> Integer
readonly
The AFK timeout of the guild.
-
#approximate_member_count -> Integer
readonly
The approxmate amount of members in the guild.
-
#approximate_presence_count -> Integer
readonly
The approxmate amount of non-offline members in the guild.
-
#available -> Boolean
(also: #available?)
readonly
Whether the guild is available.
- #banner -> Discorb::Asset? readonly
-
#channels -> Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}
readonly
A dictionary of channels in the guild.
-
#default_message_notifications -> :all_messages, :only_mentions
readonly
The default message notification level of the guild.
-
#description -> String
readonly
The description of the guild.
-
#discovery_splash -> Discorb::Asset
readonly
The discovery splash of the guild.
-
#emojis -> Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}
readonly
A dictionary of custom emojis in the guild.
-
#explicit_content_filter -> :disabled_in_text, ...
readonly
The explict content filter level of the guild.
-
#features -> Array<Symbol>
readonly
Features that are enabled in the guild.
-
#icon -> Discorb::Asset
readonly
The icon of the guild.
-
#id -> Discorb::Snowflake
readonly
ID of the guild.
-
#joined_at -> Time
readonly
Time that representing when bot has joined the guild.
-
#large -> Boolean
(also: #large?)
readonly
Whether the guild is large.
-
#max_presences -> Integer
readonly
Number of online members in the guild.
-
#max_video_channel_users -> Integer
readonly
The maximum amount of users in a video channel.
-
#member_count -> Integer
readonly
The amount of members in the guild.
-
#members -> Discorb::Dictionary{Discorb::Snowflake => Discorb::Member}
readonly
A dictionary of members in the guild.
-
#mfa_level -> :none, :elevated
readonly
The MFA level of the guild.
-
#name -> String
readonly
The name of the guild.
-
#nsfw_level -> :default, ...
readonly
The nsfw level of the guild.
-
#owner -> Boolean
(also: #owner?)
readonly
Whether the client is the owner of the guild.
-
#owner_id -> Discorb::Snowflake
readonly
ID of the guild owner.
-
#permissions -> Discorb::Permission
readonly
The bot's permission in the guild.
-
#preferred_locale -> Symbol
readonly
The preffered language of the guild.
-
#premium_subscription_count -> Integer
readonly
The amount of premium subscriptions (Server Boosts) the guild has.
-
#premium_tier -> Integer
readonly
The premium tier (Boost Level) of the guild.
-
#presences -> Discorb::Dictionary{Discorb::User => Discorb::Presence}
readonly
A dictionary of presence in the guild.
-
#roles -> Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}
readonly
A dictionary of roles in the guild.
-
#splash -> Discorb::Asset
readonly
The splash of the guild.
-
#stage_instances -> Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}
readonly
A dictionary of stage instances in the guild.
-
#system_channel_flags -> Discorb::Guild::SystemChannelFlag
readonly
The flag for the system channel.
-
#threads -> Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel}
readonly
A dictionary of threads in the guild.
-
#unavailable -> Boolean
readonly
Whether the guild is unavailable.
- #vanity_url_code -> String? readonly
-
#verification_level -> :none, ...
readonly
The verification level of the guild.
-
#voice_states -> Discorb::Dictionary{Discorb::User => Discorb::VoiceState}
readonly
A dictionary of voice states in the guild.
-
#welcome_screen -> Discorb::WelcomeScreen
readonly
The welcome screen of the guild.
-
#widget_enabled -> Boolean
(also: #widget_enabled?)
readonly
Whether the guild enabled the widget.
Class Method Summary collapse
-
.banner(guild_id, style: "banner") -> String
Returns a banner url from the guild's ID.
Instance Method Summary collapse
- #afk_channel -> Object
-
#ban_member(member, delete_message_days: 0, reason: nil) -> Discorb::Guild::Ban
Ban a member from the guild.
-
#banned?(user) -> Boolean
Checks the user was banned from the guild.
-
#create_category_channel(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::CategoryChannel
(also: #create_category)
Create a new category channel.
-
#create_emoji(name, image, roles: []) -> Discorb::CustomEmoji
Create a custom emoji.
-
#create_news_channel(name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::NewsChannel
Create a new news channel.
-
#create_role(name = nil, color: nil, hoist: nil, mentionable: nil, reason: nil) -> Discorb::Role
Create a role in the guild.
-
#create_stage_channel(name, bitrate: 64, position: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::StageChannel
Create a new stage channel.
-
#create_template(name, description = nil, reason: nil) -> Discorb::GuildTemplate
Create a new template in the guild.
-
#create_text_channel(name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::TextChannel
Create a new text channel.
-
#create_voice_channel(name, bitrate: 64, user_limit: nil, position: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::VoiceChannel
Create a new voice channel.
-
#edit_nickname(nickname, reason: nil) -> Object
(also: #edit_nick, #modify_nickname)
Change nickname of client member.
-
#fetch_active_threads -> Array<Discorb::ThreadChannel>
Fetch a list of active threads in the guild.
-
#fetch_audit_log -> Discorb::AuditLog
Fetch audit log of the guild.
-
#fetch_ban(user) -> Discorb::Guild::Ban?
Fetch a ban in the guild.
-
#fetch_bans -> Array<Discorb::Guild::Ban>
Fetch a list of bans in the guild.
-
#fetch_channels -> Array<Discorb::Channel>
Fetch channels of the guild.
-
#fetch_emoji(id) -> Discorb::CustomEmoji
Fetch emoji id of the guild.
-
#fetch_emoji_list -> Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}
(also: #fetch_emojis)
Fetch emoji list of the guild.
-
#fetch_integrations -> Array<Discorb::Integration>
Fetch integrations in the guild.
-
#fetch_invites -> Array<Invite>
Fetch invites in the guild.
-
#fetch_member(id) -> Discorb::Member?
Fetch a member in the guild.
-
#fetch_member_named -> Discorb::Member?
Almost the same as #fetch_members_named, but returns a single member.
-
#fetch_members_named(name, limit: 1) -> Array<Discorb::Member>
Search for members by name in the guild.
-
#fetch_prune(days = 7, roles: []) -> Integer
Fetch how many members will be pruned.
-
#fetch_roles -> Array<Discorb::Role>
Fetch a list of roles in the guild.
-
#fetch_sticker(id) -> Discorb::Sticker::GuildSticker?
Fetch the sticker by ID.
-
#fetch_stickers -> Array<Discorb::Sticker::GuildSticker>
Fetch stickers in the guild.
-
#fetch_template -> Discorb::GuildTemplate?
Almost the same as #fetch_templates, but returns a single template.
-
#fetch_templates -> Discorb::GuildTemplate
Fetch templates in the guild.
-
#fetch_vanity_invite -> Discorb::Guild::VanityInvite
Fetch the vanity URL of the guild.
-
#fetch_voice_regions -> Array<Discorb::VoiceRegion>
Fetch voice regions that are available in the guild.
-
#fetch_webhooks -> Array<Discorb::Webhook>
Fetch webhooks of the guild.
-
#fetch_welcome_screen -> Discorb::Guild::WelcomeScreen
Fetch the welcome screen of the guild.
-
#fetch_widget -> Discorb::Guild::Widget
Fetch the widget of the guild.
- #inspect -> Object
-
#kick_member(member, reason: nil) -> Object
Kick a member from the guild.
-
#leave! -> Object
Leave the guild.
- #me -> Object
-
#prune(days = 7, roles: [], reason: nil) -> Integer
Prune members from the guild.
- #public_updates_channel -> Object
- #rules_channel -> Object
- #system_channel -> Object
-
#unban_user(user, reason: nil) -> Object
Unban a user from the guild.
Methods inherited from DiscordModel
Instance Attribute Details
#afk_timeout -> Integer (readonly)
Returns The AFK timeout of the guild.
21 22 23 |
# File 'lib/discorb/guild.rb', line 21 def afk_timeout @afk_timeout end |
#approximate_member_count -> Integer (readonly)
Returns The approxmate amount of members in the guild.
72 73 74 |
# File 'lib/discorb/guild.rb', line 72 def approximate_member_count @approximate_member_count end |
#approximate_presence_count -> Integer (readonly)
Returns The approxmate amount of non-offline members in the guild.
74 75 76 |
# File 'lib/discorb/guild.rb', line 74 def approximate_presence_count @approximate_presence_count end |
#available -> Boolean (readonly) Also known as: available?
Returns Whether the guild is available.
97 98 99 |
# File 'lib/discorb/guild.rb', line 97 def available @available end |
#banner -> Discorb::Asset? (readonly)
61 62 63 |
# File 'lib/discorb/guild.rb', line 61 def @banner end |
#channels -> Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel} (readonly)
Returns A dictionary of channels in the guild.
47 48 49 |
# File 'lib/discorb/guild.rb', line 47 def channels @channels end |
#default_message_notifications -> :all_messages, :only_mentions (readonly)
Returns The default message notification level of the guild.
84 85 86 |
# File 'lib/discorb/guild.rb', line 84 def @default_message_notifications end |
#description -> String (readonly)
Returns The description of the guild.
58 59 60 |
# File 'lib/discorb/guild.rb', line 58 def description @description end |
#discovery_splash -> Discorb::Asset (readonly)
Returns The discovery splash of the guild.
15 16 17 |
# File 'lib/discorb/guild.rb', line 15 def discovery_splash @discovery_splash end |
#emojis -> Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji} (readonly)
Returns A dictionary of custom emojis in the guild.
25 26 27 |
# File 'lib/discorb/guild.rb', line 25 def emojis @emojis end |
#explicit_content_filter -> :disabled_in_text, ... (readonly)
Returns The explict content filter level of the guild.
86 87 88 |
# File 'lib/discorb/guild.rb', line 86 def explicit_content_filter @explicit_content_filter end |
#features -> Array<Symbol> (readonly)
Returns features that are enabled in the guild.
28 29 30 |
# File 'lib/discorb/guild.rb', line 28 def features @features end |
#icon -> Discorb::Asset (readonly)
Returns The icon of the guild.
40 41 42 |
# File 'lib/discorb/guild.rb', line 40 def icon @icon end |
#id -> Discorb::Snowflake (readonly)
Returns ID of the guild.
9 10 11 |
# File 'lib/discorb/guild.rb', line 9 def id @id end |
#joined_at -> Time (readonly)
Returns Time that representing when bot has joined the guild.
34 35 36 |
# File 'lib/discorb/guild.rb', line 34 def joined_at @joined_at end |
#large -> Boolean (readonly) Also known as: large?
Returns Whether the guild is large.
91 92 93 |
# File 'lib/discorb/guild.rb', line 91 def large @large end |
#max_presences -> Integer (readonly)
Returns Number of online members in the guild.
53 54 55 |
# File 'lib/discorb/guild.rb', line 53 def max_presences @max_presences end |
#max_video_channel_users -> Integer (readonly)
Returns The maximum amount of users in a video channel.
70 71 72 |
# File 'lib/discorb/guild.rb', line 70 def max_video_channel_users @max_video_channel_users end |
#member_count -> Integer (readonly)
Returns The amount of members in the guild.
38 39 40 |
# File 'lib/discorb/guild.rb', line 38 def member_count @member_count end |
#members -> Discorb::Dictionary{Discorb::Snowflake => Discorb::Member} (readonly)
You must enable GUILD_MEMBERS
intent to use this method.
Returns A dictionary of members in the guild.
45 46 47 |
# File 'lib/discorb/guild.rb', line 45 def members @members end |
#mfa_level -> :none, :elevated (readonly)
Returns The MFA level of the guild.
30 31 32 |
# File 'lib/discorb/guild.rb', line 30 def mfa_level @mfa_level end |
#name -> String (readonly)
Returns 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.
78 79 80 |
# File 'lib/discorb/guild.rb', line 78 def nsfw_level @nsfw_level end |
#owner -> Boolean (readonly) Also known as: owner?
Returns Whether the client is the owner of the guild.
88 89 90 |
# File 'lib/discorb/guild.rb', line 88 def owner @owner end |
#owner_id -> Discorb::Snowflake (readonly)
Returns ID of the guild owner.
17 18 19 |
# File 'lib/discorb/guild.rb', line 17 def owner_id @owner_id end |
#permissions -> Discorb::Permission (readonly)
Returns The bot's permission in the guild.
19 20 21 |
# File 'lib/discorb/guild.rb', line 19 def @permissions end |
#preferred_locale -> Symbol (readonly)
This modifies the language code, -
will be replaced with _
.
Returns The preffered language of the guild.
68 69 70 |
# File 'lib/discorb/guild.rb', line 68 def preferred_locale @preferred_locale end |
#premium_subscription_count -> Integer (readonly)
Returns The amount of premium subscriptions (Server Boosts) the guild has.
65 66 67 |
# File 'lib/discorb/guild.rb', line 65 def premium_subscription_count @premium_subscription_count end |
#premium_tier -> Integer (readonly)
Returns The premium tier (Boost Level) of the guild.
63 64 65 |
# File 'lib/discorb/guild.rb', line 63 def premium_tier @premium_tier end |
#presences -> Discorb::Dictionary{Discorb::User => Discorb::Presence} (readonly)
Returns A dictionary of presence in the guild.
51 52 53 |
# File 'lib/discorb/guild.rb', line 51 def presences @presences end |
#roles -> Discorb::Dictionary{Discorb::Snowflake => Discorb::Role} (readonly)
Returns A dictionary of roles in the guild.
23 24 25 |
# File 'lib/discorb/guild.rb', line 23 def roles @roles end |
#splash -> Discorb::Asset (readonly)
Returns The splash of the guild.
13 14 15 |
# File 'lib/discorb/guild.rb', line 13 def splash @splash end |
#stage_instances -> Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance} (readonly)
Returns A dictionary of stage instances in the guild.
80 81 82 |
# File 'lib/discorb/guild.rb', line 80 def stage_instances @stage_instances end |
#system_channel_flags -> Discorb::Guild::SystemChannelFlag (readonly)
Returns The flag for the system channel.
32 33 34 |
# File 'lib/discorb/guild.rb', line 32 def system_channel_flags @system_channel_flags end |
#threads -> Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel} (readonly)
Returns A dictionary of threads in the guild.
49 50 51 |
# File 'lib/discorb/guild.rb', line 49 def threads @threads end |
#unavailable -> Boolean (readonly)
Returns Whether the guild is unavailable.
36 37 38 |
# File 'lib/discorb/guild.rb', line 36 def unavailable @unavailable end |
#vanity_url_code -> String? (readonly)
56 57 58 |
# File 'lib/discorb/guild.rb', line 56 def vanity_url_code @vanity_url_code end |
#verification_level -> :none, ... (readonly)
Returns The verification level of the guild.
82 83 84 |
# File 'lib/discorb/guild.rb', line 82 def verification_level @verification_level end |
#voice_states -> Discorb::Dictionary{Discorb::User => Discorb::VoiceState} (readonly)
Returns A dictionary of voice states in the guild.
42 43 44 |
# File 'lib/discorb/guild.rb', line 42 def voice_states @voice_states end |
#welcome_screen -> Discorb::WelcomeScreen (readonly)
Returns The welcome screen of the guild.
76 77 78 |
# File 'lib/discorb/guild.rb', line 76 def welcome_screen @welcome_screen end |
#widget_enabled -> Boolean (readonly) Also known as: widget_enabled?
Returns Whether the guild enabled the widget.
94 95 96 |
# File 'lib/discorb/guild.rb', line 94 def @widget_enabled end |
Class Method Details
.banner(guild_id, style: "banner") -> String
Returns a banner url from the guild's ID.
1042 1043 1044 |
# File 'lib/discorb/guild.rb', line 1042 def (guild_id, style: "banner") "#{Discorb::API_BASE_URL}/guilds/#{guild_id}/widget.png&style=#{style}" end |
Instance Method Details
#afk_channel -> Object
136 137 138 |
# 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) -> Discorb::Guild::Ban
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Ban a member from the guild.
643 644 645 646 647 648 649 650 |
# 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: }, audit_log_reason: reason, ).wait Ban.new(@client, self, data) end end |
#banned?(user) -> Boolean
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Checks the user was banned from the guild.
626 627 628 629 630 |
# File 'lib/discorb/guild.rb', line 626 def banned?(user) Async do !fetch_ban(user).wait.nil? end end |
#create_category_channel(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil) -> Discorb::CategoryChannel Also known as: create_category
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a new category channel.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# 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 payload[: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_emoji(name, image, roles: []) -> Discorb::CustomEmoji
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a custom emoji.
222 223 224 225 226 227 228 229 230 231 232 |
# 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) -> Discorb::NewsChannel
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a new news channel.
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# 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 payload[: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) -> Discorb::Role
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a role in the guild.
693 694 695 696 697 698 699 700 701 702 703 704 705 |
# 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) -> Discorb::StageChannel
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a new stage channel.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# 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 payload[: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) -> Discorb::GuildTemplate
Create a new template in the guild.
902 903 904 905 906 907 908 909 |
# 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) -> Discorb::TextChannel
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a new text channel.
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 |
# 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 payload[: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) -> Discorb::VoiceChannel
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Create a new voice channel.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# 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 payload[: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_nickname(nickname, reason: nil) -> Object Also known as: edit_nick, modify_nickname
Change nickname of client member.
559 560 561 562 563 |
# 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_active_threads -> Array<Discorb::ThreadChannel>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch a list of active threads in the guild.
494 495 496 497 498 499 |
# 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 -> Discorb::AuditLog
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch audit log of the guild.
255 256 257 258 259 260 |
# 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) -> Discorb::Guild::Ban?
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch a ban in the guild.
607 608 609 610 611 612 613 614 615 |
# 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 -> Array<Discorb::Guild::Ban>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch a list of bans in the guild.
590 591 592 593 594 595 |
# 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 -> Array<Discorb::Channel>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch channels of the guild.
269 270 271 272 273 274 |
# 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) -> Discorb::CustomEmoji
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
This querys the API every time. We recommend using #emojis instead.
Fetch emoji id of the guild.
206 207 208 209 |
# 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 -> Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji} Also known as: fetch_emojis
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
This querys the API every time. We recommend using #emojis instead.
Fetch emoji list of the guild.
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# 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 -> Array<Discorb::Integration>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch integrations in the guild.
784 785 786 787 788 789 |
# 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 -> Array<Invite>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch invites in the guild.
770 771 772 773 774 775 |
# 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) -> Discorb::Member?
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
You must enable GUILD_MEMBERS
intent to use this method.
Fetch a member in the guild.
512 513 514 515 516 517 518 519 520 |
# 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 -> Discorb::Member?
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Almost the same as #fetch_members_named, but returns a single member.
547 548 549 550 551 |
# 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) -> Array<Discorb::Member>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Search for members by name in the guild.
532 533 534 535 536 537 |
# 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: []) -> Integer
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch how many members will be pruned.
717 718 719 720 721 722 723 724 725 726 727 |
# 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 -> Array<Discorb::Role>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch a list of roles in the guild.
673 674 675 676 677 678 |
# 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) -> Discorb::Sticker::GuildSticker?
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch the sticker by ID.
857 858 859 860 861 862 863 864 865 |
# 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 -> Array<Discorb::Sticker::GuildSticker>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch stickers in the guild.
840 841 842 843 844 845 |
# 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 -> Discorb::GuildTemplate?
Almost the same as #fetch_templates, but returns a single template.
887 888 889 890 891 |
# File 'lib/discorb/guild.rb', line 887 def fetch_template Async do fetch_templates.wait.first end end |
#fetch_templates -> Discorb::GuildTemplate
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch templates in the guild.
874 875 876 877 878 879 |
# 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 -> Discorb::Guild::VanityInvite
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch the vanity URL of the guild.
812 813 814 815 816 817 |
# 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 -> Array<Discorb::VoiceRegion>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch voice regions that are available in the guild.
756 757 758 759 760 761 |
# 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 -> Array<Discorb::Webhook>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch webhooks of the guild.
241 242 243 244 245 246 |
# 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 -> Discorb::Guild::WelcomeScreen
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch the welcome screen of the guild.
826 827 828 829 830 831 |
# 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 -> Discorb::Guild::Widget
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Fetch the widget of the guild.
798 799 800 801 802 803 |
# File 'lib/discorb/guild.rb', line 798 def Async do _resp, data = @client.http.get("/guilds/#{@id}/widget").wait Widget.new(@client, @id, data) end end |
#inspect -> Object
152 153 154 |
# File 'lib/discorb/guild.rb', line 152 def inspect "#<#{self.class} \"#{@name}\" id=#{@id}>" end |
#kick_member(member, reason: nil) -> Object
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Kick a member from the guild.
577 578 579 580 581 |
# 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! -> Object
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Leave the guild.
165 166 167 168 169 170 |
# 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 -> Object
156 157 158 |
# File 'lib/discorb/guild.rb', line 156 def me @members[@client.user.id] end |
#prune(days = 7, roles: [], reason: nil) -> Integer
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Prune members from the guild.
740 741 742 743 744 745 746 747 |
# 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 -> Object
148 149 150 |
# File 'lib/discorb/guild.rb', line 148 def public_updates_channel @client.channels[@public_updates_channel_id] end |
#rules_channel -> Object
144 145 146 |
# File 'lib/discorb/guild.rb', line 144 def rules_channel @client.channels[@rules_channel_id] end |
#system_channel -> Object
140 141 142 |
# File 'lib/discorb/guild.rb', line 140 def system_channel @client.channels[@system_channel_id] end |
#unban_user(user, reason: nil) -> Object
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Unban a user from the guild.
660 661 662 663 664 |
# 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 |