Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Includes:
- IDObject, ServerAttributes
- Defined in:
- lib/discordrb/data/server.rb
Overview
A server on Discord
Constant Summary collapse
- VERIFICATION_LEVELS =
A map of possible server verification levels to symbol names
{ none: 0, low: 1, medium: 2, high: 3, very_high: 4 }.freeze
- NOTIFICATION_LEVELS =
A map of possible message notification levels to symbol names
{ all_messages: 0, only_mentions: 1 }.freeze
- FILTER_LEVELS =
A map of possible content filter levels to symbol names
{ disabled: 0, members_without_roles: 1, all_members: 2 }.freeze
Instance Attribute Summary collapse
-
#afk_timeout ⇒ Integer
The amount of time after which a voice user gets moved into the AFK channel, in seconds.
-
#boost_level ⇒ Integer
readonly
The server's Nitro boost level.
-
#booster_count ⇒ Integer
readonly
The server's amount of Nitro boosters.
-
#channels ⇒ Array<Channel>
readonly
An array of all the channels (text and voice) on this server.
-
#emoji ⇒ Hash<Integer => Emoji>
(also: #emojis)
readonly
A hash of all the emoji available on this server.
-
#features ⇒ Array<Symbol>
readonly
The features of the server (eg. "INVITE_SPLASH").
-
#large ⇒ true, false
(also: #large?)
readonly
it means the members list may be inaccurate for a couple seconds after starting up the bot.
-
#member_count ⇒ Integer
readonly
The absolute number of members on this server, offline or not.
-
#region_id ⇒ String
readonly
The ID of the region the server is on (e.g.
amsterdam). -
#roles ⇒ Array<Role>
readonly
An array of all the roles created on this server.
-
#voice_states ⇒ Hash<Integer => VoiceState>
readonly
The hash (user ID => voice state) of voice states of members on this server.
Attributes included from ServerAttributes
Attributes included from IDObject
Instance Method Summary collapse
-
#add_emoji(name, image, roles = [], reason: nil) ⇒ Emoji
Adds a new custom emoji on this server.
-
#add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false) ⇒ Member?
Adds a member to this guild that has granted this bot's application an OAuth2 access token with the
guilds.joinscope. -
#afk_channel ⇒ Channel?
The AFK voice channel of this server, or
nilif none is set. -
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
-
#any_emoji? ⇒ true, false
(also: #has_emoji?, #emoji?)
Whether this server has any emoji or not.
-
#audit_logs(action: nil, user: nil, limit: 50, before: nil) ⇒ AuditLogs
The server's audit logs.
-
#available_voice_regions ⇒ Array<VoiceRegion>
Collection of available voice regions to this guild.
-
#ban(user, message_days = 0, message_seconds: nil, reason: nil) ⇒ Object
Bans a user from this server.
-
#banner_id ⇒ String
The hexadecimal ID used to identify this server's banner image, shown by the server name.
-
#banner_url ⇒ String?
The banner image URL for the server's banner image, or
nilif there is no banner image. -
#bans(limit: nil, before_id: nil, after_id: nil) ⇒ Array<ServerBan>
Retrieve banned users from this server.
-
#begin_prune(days, reason = nil) ⇒ Integer
(also: #prune)
Prunes (kicks) an amount of members for inactivity.
-
#bot ⇒ Member
The bot's own
Memberon this server. -
#bot_members ⇒ Array<Member>
An array of all the bot members on this server.
-
#bulk_ban(users:, message_seconds: 0, reason: nil) ⇒ BulkBan
Ban up to 200 users from this server in one go.
-
#categories ⇒ Array<Channel>
An array of category channels on this server.
-
#create_channel(name, type = 0, topic: nil, bitrate: nil, user_limit: nil, permission_overwrites: nil, parent: nil, nsfw: false, rate_limit_per_user: nil, position: nil, reason: nil) ⇒ Channel
Creates a channel on this server with the given name.
-
#create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, secondary_colour: nil, tertiary_colour: nil, icon: nil, unicode_emoji: nil, display_icon: nil, reason: nil) ⇒ Role
Creates a role on this server which can then be modified.
-
#default_channel(send_messages = false) ⇒ Channel?
(also: #general_channel)
The default channel is the text channel on this server with the highest position that the bot has Read Messages permission on.
-
#default_message_notifications ⇒ Symbol
The default message notifications settings of the server (:all = 'All messages', :mentions = 'Only @mentions').
-
#default_message_notifications=(notification_level) ⇒ Object
(also: #notification_level=)
Sets the default message notification level.
-
#delete_emoji(emoji, reason: nil) ⇒ Object
Delete a custom emoji on this server.
-
#edit_emoji(emoji, name: nil, roles: nil, reason: nil) ⇒ Emoji
Changes the name and/or role whitelist of an emoji on this server.
-
#everyone_role ⇒ Role
The @everyone role on this server.
-
#explicit_content_filter ⇒ Symbol
(also: #content_filter_level)
The explicit content filter level of the server (:none = 'Don't scan any messages.', :exclude_roles = 'Scan messages for members without a role.', :all = 'Scan messages sent by all members.').
-
#explicit_content_filter=(filter_level) ⇒ Object
Sets the server content filter.
-
#icon=(icon) ⇒ Object
Sets the server's icon.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#integrations ⇒ Array<Integration>
An array of the integrations in this server.
-
#invites ⇒ Array<Invite>
Requests a list of Invites to the server.
-
#kick(user, reason = nil) ⇒ Object
Kicks a user from this server.
-
#leave ⇒ Object
Leave the server.
-
#link ⇒ String
(also: #jump_link)
A URL that a user can use to navigate to this server in the client.
-
#max_emoji ⇒ Integer
The amount of emoji the server can have, based on its current Nitro Boost Level.
-
#member(id, request = true) ⇒ Object
Gets a member on this server based on user ID.
-
#members ⇒ Array<Member>
(also: #users)
An array of all the members on this server.
-
#modify_widget(enabled, channel, reason = nil) ⇒ Object
(also: #modify_embed)
Changes the channel on the server's widget, and sets whether it is enabled.
-
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel.
-
#name=(name) ⇒ Object
Sets the server's name.
-
#non_bot_members ⇒ Array<Member>
An array of all the non bot members on this server.
-
#online_members(include_idle: false, include_bots: true) ⇒ Array<Member>
(also: #online_users)
An array of online members on this server.
-
#orphan_channels ⇒ Array<Channel>
An array of channels on this server that are not in a category.
-
#owner ⇒ Member
The server owner.
-
#preview ⇒ ServerPreview
The preview of this server shown in the discovery page.
-
#prune_count(days) ⇒ Integer
Returns the amount of members that are candidates for pruning.
-
#region ⇒ VoiceRegion?
Voice region data for this server's region.
-
#region=(region) ⇒ Object
Moves the server to another region.
-
#role(id) ⇒ Role?
Gets a role on this server based on its ID.
-
#search_members(name:, limit: nil) ⇒ Array<Member>?
Searches a server for members that matches a username or a nickname.
-
#set_widget_channel(channel, reason = nil) ⇒ Object
(also: #set_embed_channel)
Changes the channel on the server's widget.
-
#set_widget_enabled(value, reason = nil) ⇒ Object
(also: #set_embed_enabled)
Sets whether this server's widget is enabled.
-
#splash=(splash_hash) ⇒ Object
Sets the server splash.
-
#splash_id ⇒ String
(also: #splash_hash)
The hexadecimal ID used to identify this server's splash image for their VIP invite page.
-
#splash_url ⇒ String?
The splash image URL for the server's VIP invite page.
-
#system_channel ⇒ Channel?
The system channel (used for automatic welcome messages) of a server, or
nilif none is set. -
#system_channel=(system_channel) ⇒ Object
Sets the server's system channel.
-
#text_channels ⇒ Array<Channel>
An array of text channels on this server.
-
#unban(user, reason = nil) ⇒ Object
Unbans a previously banned user from this server.
-
#verification_level ⇒ Symbol
The verification level of the server (:none = none, :low = 'Must have a verified email on their Discord account', :medium = 'Has to be registered with Discord for at least 5 minutes', :high = 'Has to be a member of this server for at least 10 minutes', :very_high = 'Must have a verified phone on their Discord account').
-
#verification_level=(level) ⇒ Object
Sets the verification level of the server.
-
#voice_channels ⇒ Array<Channel>
An array of voice channels on this server.
-
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the server.
-
#widget_banner_url(style) ⇒ String?
The widget banner URL to the server that displays the amount of online members, server icon and server name in a stylish way.
-
#widget_channel ⇒ Channel?
(also: #embed_channel)
The channel the server widget will make an invite for.
-
#widget_channel=(channel) ⇒ Object
(also: #embed_channel=)
Changes the channel on the server's widget.
-
#widget_enabled=(value) ⇒ Object
(also: #embed_enabled=)
Sets whether this server's widget is enabled.
-
#widget_enabled? ⇒ true, false
(also: #widget?, #embed_enabled, #embed?)
Whether or not the server has widget enabled.
-
#widget_url ⇒ String?
The widget URL to the server that displays the amount of online members in a stylish way.
Methods included from ServerAttributes
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#afk_timeout ⇒ Integer
Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.
51 52 53 |
# File 'lib/discordrb/data/server.rb', line 51 def afk_timeout @afk_timeout end |
#boost_level ⇒ Integer (readonly)
The server's Nitro boost level.
62 63 64 |
# File 'lib/discordrb/data/server.rb', line 62 def boost_level @boost_level end |
#booster_count ⇒ Integer (readonly)
The server's amount of Nitro boosters.
58 59 60 |
# File 'lib/discordrb/data/server.rb', line 58 def booster_count @booster_count end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
30 31 32 |
# File 'lib/discordrb/data/server.rb', line 30 def channels @channels end |
#emoji ⇒ Hash<Integer => Emoji> (readonly) Also known as: emojis
Returns a hash of all the emoji available on this server.
36 37 38 |
# File 'lib/discordrb/data/server.rb', line 36 def emoji @emoji end |
#features ⇒ Array<Symbol> (readonly)
Returns the features of the server (eg. "INVITE_SPLASH").
45 46 47 |
# File 'lib/discordrb/data/server.rb', line 45 def features @features end |
#large ⇒ true, false (readonly) Also known as: large?
it means the members list may be inaccurate for a couple seconds after starting up the bot.
41 42 43 |
# File 'lib/discordrb/data/server.rb', line 41 def large @large end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
48 49 50 |
# File 'lib/discordrb/data/server.rb', line 48 def member_count @member_count end |
#region_id ⇒ String (readonly)
Returns the ID of the region the server is on (e.g. amsterdam).
27 28 29 |
# File 'lib/discordrb/data/server.rb', line 27 def region_id @region_id end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
33 34 35 |
# File 'lib/discordrb/data/server.rb', line 33 def roles @roles end |
#voice_states ⇒ Hash<Integer => VoiceState> (readonly)
Returns the hash (user ID => voice state) of voice states of members on this server.
54 55 56 |
# File 'lib/discordrb/data/server.rb', line 54 def voice_states @voice_states end |
Instance Method Details
#add_emoji(name, image, roles = [], reason: nil) ⇒ Emoji
Adds a new custom emoji on this server.
563 564 565 566 567 568 569 |
# File 'lib/discordrb/data/server.rb', line 563 def add_emoji(name, image, roles = [], reason: nil) image = image.respond_to?(:read) ? Discordrb.encode64(image) : image data = JSON.parse(API::Server.add_emoji(@bot.token, @id, image, name, roles.map(&:resolve_id), reason)) new_emoji = Emoji.new(data, @bot, self) @emoji[new_emoji.id] = new_emoji end |
#add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false) ⇒ Member?
Your bot must be present in this server, and have permission to create instant invites for this to work.
Adds a member to this guild that has granted this bot's application an OAuth2 access token
with the guilds.join scope.
For more information about Discord's OAuth2 implementation, see: https://discord.com/developers/docs/topics/oauth2
272 273 274 275 276 277 278 279 |
# File 'lib/discordrb/data/server.rb', line 272 def add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false) user_id = user.resolve_id roles = roles.is_a?(Array) ? roles.map(&:resolve_id) : [roles.resolve_id] response = API::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute) return nil if response.empty? add_member Member.new(JSON.parse(response), self, @bot) end |
#afk_channel ⇒ Channel?
Returns the AFK voice channel of this server, or nil if none is set.
850 851 852 |
# File 'lib/discordrb/data/server.rb', line 850 def afk_channel @bot.channel(@afk_channel_id) if @afk_channel_id end |
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
725 726 727 |
# File 'lib/discordrb/data/server.rb', line 725 def afk_channel=(afk_channel) update_server_data(afk_channel_id: afk_channel.resolve_id) end |
#any_emoji? ⇒ true, false Also known as: has_emoji?, emoji?
Returns whether this server has any emoji or not.
813 814 815 |
# File 'lib/discordrb/data/server.rb', line 813 def any_emoji? @emoji.any? end |
#audit_logs(action: nil, user: nil, limit: 50, before: nil) ⇒ AuditLogs
Returns The server's audit logs.
173 174 175 176 177 178 179 180 |
# File 'lib/discordrb/data/server.rb', line 173 def audit_logs(action: nil, user: nil, limit: 50, before: nil) raise 'Invalid audit log action!' if action && AuditLogs::ACTIONS.key(action).nil? action = AuditLogs::ACTIONS.key(action) user = user.resolve_id if user before = before.resolve_id if before AuditLogs.new(self, @bot, JSON.parse(API::Server.audit_logs(@bot.token, @id, limit, user, action, before))) end |
#available_voice_regions ⇒ Array<VoiceRegion>
Returns collection of available voice regions to this guild.
692 693 694 695 696 697 698 699 |
# File 'lib/discordrb/data/server.rb', line 692 def available_voice_regions return @available_voice_regions if @available_voice_regions @available_voice_regions = {} data = JSON.parse API::Server.regions(@bot.token, @id) @available_voice_regions = data.map { |e| VoiceRegion.new e } end |
#ban(user, message_days = 0, message_seconds: nil, reason: nil) ⇒ Object
Bans a user from this server.
634 635 636 637 638 639 640 641 642 |
# File 'lib/discordrb/data/server.rb', line 634 def ban(user, = 0, message_seconds: nil, reason: nil) = if != 0 && * 86_400 else || 0 end API::Server.ban_user!(@bot.token, @id, user.resolve_id, , reason) end |
#banner_id ⇒ String
Returns the hexadecimal ID used to identify this server's banner image, shown by the server name.
371 372 373 |
# File 'lib/discordrb/data/server.rb', line 371 def @banner_id ||= JSON.parse(API::Server.resolve(@bot.token, @id))['banner'] end |
#banner_url ⇒ String?
Returns the banner image URL for the server's banner image, or
nil if there is no banner image.
377 378 379 380 381 382 |
# File 'lib/discordrb/data/server.rb', line 377 def if @banner_id.nil? return unless API.(@id, @banner_id) end |
#bans(limit: nil, before_id: nil, after_id: nil) ⇒ Array<ServerBan>
Retrieve banned users from this server.
622 623 624 625 626 627 |
# File 'lib/discordrb/data/server.rb', line 622 def bans(limit: nil, before_id: nil, after_id: nil) response = JSON.parse(API::Server.bans(@bot.token, @id, limit, before_id, after_id)) response.map do |e| ServerBan.new(self, User.new(e['user'], @bot), e['reason']) end end |
#begin_prune(days, reason = nil) ⇒ Integer Also known as: prune
Prunes (kicks) an amount of members for inactivity
297 298 299 300 301 302 |
# File 'lib/discordrb/data/server.rb', line 297 def begin_prune(days, reason = nil) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = JSON.parse API::Server.begin_prune(@bot.token, @id, days, reason) response['pruned'] end |
#bot ⇒ Member
Returns the bot's own Member on this server.
157 158 159 |
# File 'lib/discordrb/data/server.rb', line 157 def bot member(@bot.profile) end |
#bot_members ⇒ Array<Member>
Returns an array of all the bot members on this server.
147 148 149 |
# File 'lib/discordrb/data/server.rb', line 147 def bot_members members.select(&:bot_account?) end |
#bulk_ban(users:, message_seconds: 0, reason: nil) ⇒ BulkBan
Ban up to 200 users from this server in one go.
656 657 658 659 660 661 662 663 |
# File 'lib/discordrb/data/server.rb', line 656 def bulk_ban(users:, message_seconds: 0, reason: nil) raise ArgumentError, 'Can only ban between 1 and 200 users!' unless users.size.between?(1, 200) return ban(users.first, 0, message_seconds: , reason: reason) if users.size == 1 response = API::Server.bulk_ban(@bot.token, @id, users.map(&:resolve_id), , reason) BulkBan.new(JSON.parse(response), self, reason) end |
#categories ⇒ Array<Channel>
Returns an array of category channels on this server.
317 318 319 |
# File 'lib/discordrb/data/server.rb', line 317 def categories @channels.select(&:category?) end |
#create_channel(name, type = 0, topic: nil, bitrate: nil, user_limit: nil, permission_overwrites: nil, parent: nil, nsfw: false, rate_limit_per_user: nil, position: nil, reason: nil) ⇒ Channel
If parent is provided, permission overwrites have the follow behavior:
- If overwrites is null, the new channel inherits the parent's permissions.
- If overwrites is [], the new channel inherits the parent's permissions.
- If you supply one or more overwrites, the channel will be created with those permissions and ignore the parents.
Creates a channel on this server with the given name.
500 501 502 503 504 505 506 507 508 |
# File 'lib/discordrb/data/server.rb', line 500 def create_channel(name, type = 0, topic: nil, bitrate: nil, user_limit: nil, permission_overwrites: nil, parent: nil, nsfw: false, rate_limit_per_user: nil, position: nil, reason: nil) type = Channel::TYPES[type] if type.is_a?(Symbol) raise ArgumentError, 'Channel type must be either 0 (text), 2 (voice), 4 (category), news (5), or store (6)!' unless [0, 2, 4, 5, 6].include?(type) .map! { |e| e.is_a?(Overwrite) ? e.to_hash : e } if .is_a?(Array) parent_id = parent.respond_to?(:resolve_id) ? parent.resolve_id : nil response = API::Server.create_channel(@bot.token, @id, name, type, topic, bitrate, user_limit, , parent_id, nsfw, rate_limit_per_user, position, reason) Channel.new(JSON.parse(response), @bot) end |
#create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, secondary_colour: nil, tertiary_colour: nil, icon: nil, unicode_emoji: nil, display_icon: nil, reason: nil) ⇒ Role
Creates a role on this server which can then be modified. It will be initialized with the regular role defaults the client uses unless specified, i.e. name is "new role", permissions are the default, colour is the default etc.
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/discordrb/data/server.rb', line 525 def create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, secondary_colour: nil, tertiary_colour: nil, icon: nil, unicode_emoji: nil, display_icon: nil, reason: nil) colour = colour.respond_to?(:combined) ? colour.combined : colour = if .is_a?(Array) Permissions.bits() elsif .respond_to?(:bits) .bits else end icon = icon.respond_to?(:read) ? Discordrb.encode64(icon) : icon colours = { primary_color: colour&.to_i, tertiary_color: tertiary_colour&.to_i, secondary_color: secondary_colour&.to_i } if display_icon.is_a?(String) unicode_emoji = display_icon elsif display_icon.respond_to?(:read) icon = Discordrb.encode64(display_icon) end response = API::Server.create_role(@bot.token, @id, name, nil, hoist, mentionable, &.to_s, reason, colours, icon, unicode_emoji) role = Role.new(JSON.parse(response), @bot, self) @roles << role role end |
#default_channel(send_messages = false) ⇒ Channel? Also known as: general_channel
The default channel is the text channel on this server with the highest position that the bot has Read Messages permission on.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/discordrb/data/server.rb', line 89 def default_channel( = false) bot_member = member(@bot.profile) text_channels.sort_by { |e| [e.position, e.id] }.find do |e| if bot_member.(e) && bot_member.(e) else bot_member.(e) end end end |
#default_message_notifications ⇒ Symbol
Returns the default message notifications settings of the server (:all = 'All messages', :mentions = 'Only @mentions').
770 771 772 |
# File 'lib/discordrb/data/server.rb', line 770 def NOTIFICATION_LEVELS.key @default_message_notifications end |
#default_message_notifications=(notification_level) ⇒ Object Also known as: notification_level=
Sets the default message notification level
776 777 778 779 780 |
# File 'lib/discordrb/data/server.rb', line 776 def (notification_level) notification_level = NOTIFICATION_LEVELS[notification_level] if notification_level.is_a?(Symbol) update_server_data(default_message_notifications: notification_level) end |
#delete_emoji(emoji, reason: nil) ⇒ Object
Delete a custom emoji on this server
574 575 576 |
# File 'lib/discordrb/data/server.rb', line 574 def delete_emoji(emoji, reason: nil) API::Server.delete_emoji(@bot.token, @id, emoji.resolve_id, reason) end |
#edit_emoji(emoji, name: nil, roles: nil, reason: nil) ⇒ Emoji
Changes the name and/or role whitelist of an emoji on this server.
584 585 586 587 588 589 |
# File 'lib/discordrb/data/server.rb', line 584 def edit_emoji(emoji, name: nil, roles: nil, reason: nil) emoji = @emoji[emoji.resolve_id] data = JSON.parse(API::Server.edit_emoji(@bot.token, @id, emoji.resolve_id, name || emoji.name, (roles || emoji.roles).map(&:resolve_id), reason)) new_emoji = Emoji.new(data, @bot, self) @emoji[new_emoji.id] = new_emoji end |
#everyone_role ⇒ Role
Returns The @everyone role on this server.
103 104 105 |
# File 'lib/discordrb/data/server.rb', line 103 def everyone_role role(@id) end |
#explicit_content_filter ⇒ Symbol Also known as: content_filter_level
Returns the explicit content filter level of the server (:none = 'Don't scan any messages.', :exclude_roles = 'Scan messages for members without a role.', :all = 'Scan messages sent by all members.').
798 799 800 |
# File 'lib/discordrb/data/server.rb', line 798 def explicit_content_filter FILTER_LEVELS.key @explicit_content_filter end |
#explicit_content_filter=(filter_level) ⇒ Object
Sets the server content filter.
806 807 808 809 810 |
# File 'lib/discordrb/data/server.rb', line 806 def explicit_content_filter=(filter_level) filter_level = FILTER_LEVELS[filter_level] if filter_level.is_a?(Symbol) update_server_data(explicit_content_filter: filter_level) end |
#icon=(icon) ⇒ Object
Sets the server's icon.
715 716 717 718 719 720 721 |
# File 'lib/discordrb/data/server.rb', line 715 def icon=(icon) if icon.respond_to?(:read) update_server_data(icon_id: Discordrb.encode64(icon)) else update_server_data(icon_id: icon) end end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
939 940 941 |
# File 'lib/discordrb/data/server.rb', line 939 def inspect "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} system_channel_id=#{@system_channel_id} afk_timeout=#{@afk_timeout}>" end |
#integrations ⇒ Array<Integration>
If the server has more than 50 integrations, they cannot be accessed.
Returns an array of the integrations in this server.
163 164 165 166 |
# File 'lib/discordrb/data/server.rb', line 163 def integrations integration = JSON.parse(API::Server.integrations(@bot.token, @id)) integration.map { |element| Integration.new(element, @bot, self) } end |
#invites ⇒ Array<Invite>
Requests a list of Invites to the server.
829 830 831 832 |
# File 'lib/discordrb/data/server.rb', line 829 def invites invites = JSON.parse(API::Server.invites(@bot.token, @id)) invites.map { |invite| Invite.new(invite, @bot) } end |
#kick(user, reason = nil) ⇒ Object
Kicks a user from this server.
668 669 670 |
# File 'lib/discordrb/data/server.rb', line 668 def kick(user, reason = nil) API::Server.remove_member(@bot.token, @id, user.resolve_id, reason) end |
#leave ⇒ Object
Leave the server.
681 682 683 |
# File 'lib/discordrb/data/server.rb', line 681 def leave API::User.leave_server(@bot.token, @id) end |
#link ⇒ String Also known as: jump_link
Returns a URL that a user can use to navigate to this server in the client.
385 386 387 |
# File 'lib/discordrb/data/server.rb', line 385 def link "https://discord.com/channels/#{@id}" end |
#max_emoji ⇒ Integer
The amount of emoji the server can have, based on its current Nitro Boost Level.
593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/discordrb/data/server.rb', line 593 def max_emoji case @boost_level when 1 100 when 2 150 when 3 250 else 50 end end |
#member(id, request = true) ⇒ Object
Gets a member on this server based on user ID
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/discordrb/data/server.rb', line 118 def member(id, request = true) id = id.resolve_id return @members[id] if member_cached?(id) return nil unless request member = @bot.member(self, id) @members[id] = member unless member.nil? rescue StandardError nil end |
#members ⇒ Array<Member> Also known as: users
Returns an array of all the members on this server.
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/discordrb/data/server.rb', line 131 def members return @members.values if @chunked @bot.debug("Members for server #{@id} not chunked yet - initiating") # If the SERVER_MEMBERS intent flag isn't set, the gateway won't respond when we ask for members. raise 'The :server_members intent is required to get server members' if @bot.gateway.intents.nobits?(INTENTS[:server_members]) @bot.request_chunks(@id) sleep 0.05 until @chunked @members.values end |
#modify_widget(enabled, channel, reason = nil) ⇒ Object Also known as: modify_embed
Changes the channel on the server's widget, and sets whether it is enabled.
241 242 243 244 245 246 247 |
# File 'lib/discordrb/data/server.rb', line 241 def (enabled, channel, reason = nil) if @widget_enabled.nil? channel_id = channel ? channel.resolve_id : @widget_channel_id response = JSON.parse(API::Server.(@bot.token, @id, enabled, channel_id, reason)) @widget_enabled = response['enabled'] @widget_channel_id = response['channel_id'] end |
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed and if the user is already connected to some voice channel on this server.
676 677 678 |
# File 'lib/discordrb/data/server.rb', line 676 def move(user, channel) API::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel&.resolve_id) end |
#name=(name) ⇒ Object
Sets the server's name.
687 688 689 |
# File 'lib/discordrb/data/server.rb', line 687 def name=(name) update_server_data(name: name) end |
#non_bot_members ⇒ Array<Member>
Returns an array of all the non bot members on this server.
152 153 154 |
# File 'lib/discordrb/data/server.rb', line 152 def non_bot_members members.reject(&:bot_account?) end |
#online_members(include_idle: false, include_bots: true) ⇒ Array<Member> Also known as: online_users
Returns an array of online members on this server.
253 254 255 256 257 |
# File 'lib/discordrb/data/server.rb', line 253 def online_members(include_idle: false, include_bots: true) @members.values.select do |e| ((include_idle ? e.idle? : false) || e.online?) && (include_bots ? true : !e.bot_account?) end end |
#orphan_channels ⇒ Array<Channel>
Returns an array of channels on this server that are not in a category.
322 323 324 |
# File 'lib/discordrb/data/server.rb', line 322 def orphan_channels @channels.reject { |c| c.parent || c.category? } end |
#owner ⇒ Member
Returns The server owner.
81 82 83 |
# File 'lib/discordrb/data/server.rb', line 81 def owner member(@owner_id) end |
#preview ⇒ ServerPreview
Returns the preview of this server shown in the discovery page.
327 328 329 |
# File 'lib/discordrb/data/server.rb', line 327 def preview @bot.server_preview(@id) end |
#prune_count(days) ⇒ Integer
Returns the amount of members that are candidates for pruning
285 286 287 288 289 290 |
# File 'lib/discordrb/data/server.rb', line 285 def prune_count(days) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = JSON.parse API::Server.prune_count(@bot.token, @id, days) response['pruned'] end |
#region ⇒ VoiceRegion?
This may return nil if this server's voice region is deprecated.
Returns voice region data for this server's region.
703 704 705 |
# File 'lib/discordrb/data/server.rb', line 703 def region available_voice_regions.find { |e| e.id == @region_id } end |
#region=(region) ⇒ Object
Moves the server to another region. This will cause a voice interruption of at most a second.
709 710 711 |
# File 'lib/discordrb/data/server.rb', line 709 def region=(region) update_server_data(region: region.to_s) end |
#role(id) ⇒ Role?
Gets a role on this server based on its ID.
110 111 112 113 |
# File 'lib/discordrb/data/server.rb', line 110 def role(id) id = id.resolve_id @roles.find { |e| e.id == id } end |
#search_members(name:, limit: nil) ⇒ Array<Member>?
Searches a server for members that matches a username or a nickname.
610 611 612 613 614 615 |
# File 'lib/discordrb/data/server.rb', line 610 def search_members(name:, limit: nil) response = JSON.parse(API::Server.search_guild_members(@bot.token, @id, name, limit)) return nil if response.empty? response.map { |mem| Member.new(mem, self, @bot) } end |
#set_widget_channel(channel, reason = nil) ⇒ Object Also known as: set_embed_channel
Changes the channel on the server's widget
232 233 234 |
# File 'lib/discordrb/data/server.rb', line 232 def (channel, reason = nil) (, channel, reason) end |
#set_widget_enabled(value, reason = nil) ⇒ Object Also known as: set_embed_enabled
Sets whether this server's widget is enabled
217 218 219 |
# File 'lib/discordrb/data/server.rb', line 217 def (value, reason = nil) (value, , reason) end |
#splash=(splash_hash) ⇒ Object
Sets the server splash
786 787 788 |
# File 'lib/discordrb/data/server.rb', line 786 def splash=(splash_hash) update_server_data(splash: splash_hash) end |
#splash_id ⇒ String Also known as: splash_hash
Returns the hexadecimal ID used to identify this server's splash image for their VIP invite page.
356 357 358 |
# File 'lib/discordrb/data/server.rb', line 356 def splash_id @splash_id ||= JSON.parse(API::Server.resolve(@bot.token, @id))['splash'] end |
#splash_url ⇒ String?
Returns the splash image URL for the server's VIP invite page.
nil if there is no splash image.
363 364 365 366 367 368 |
# File 'lib/discordrb/data/server.rb', line 363 def splash_url splash_id if @splash_id.nil? return nil unless @splash_id API.splash_url(@id, @splash_id) end |
#system_channel ⇒ Channel?
Returns the system channel (used for automatic welcome messages) of a server, or nil if none is set.
855 856 857 |
# File 'lib/discordrb/data/server.rb', line 855 def system_channel @bot.channel(@system_channel_id) if @system_channel_id end |
#system_channel=(system_channel) ⇒ Object
Sets the server's system channel.
731 732 733 |
# File 'lib/discordrb/data/server.rb', line 731 def system_channel=(system_channel) update_server_data(system_channel_id: system_channel.resolve_id) end |
#text_channels ⇒ Array<Channel>
Returns an array of text channels on this server.
307 308 309 |
# File 'lib/discordrb/data/server.rb', line 307 def text_channels @channels.select(&:text?) end |
#unban(user, reason = nil) ⇒ Object
Unbans a previously banned user from this server.
647 648 649 |
# File 'lib/discordrb/data/server.rb', line 647 def unban(user, reason = nil) API::Server.unban_user(@bot.token, @id, user.resolve_id, reason) end |
#verification_level ⇒ Symbol
Returns the verification level of the server (:none = none, :low = 'Must have a verified email on their Discord account', :medium = 'Has to be registered with Discord for at least 5 minutes', :high = 'Has to be a member of this server for at least 10 minutes', :very_high = 'Must have a verified phone on their Discord account').
751 752 753 |
# File 'lib/discordrb/data/server.rb', line 751 def verification_level VERIFICATION_LEVELS.key @verification_level end |
#verification_level=(level) ⇒ Object
Sets the verification level of the server
757 758 759 760 761 |
# File 'lib/discordrb/data/server.rb', line 757 def verification_level=(level) level = VERIFICATION_LEVELS[level] if level.is_a?(Symbol) update_server_data(verification_level: level) end |
#voice_channels ⇒ Array<Channel>
Returns an array of voice channels on this server.
312 313 314 |
# File 'lib/discordrb/data/server.rb', line 312 def voice_channels @channels.select(&:voice?) end |
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the server.
822 823 824 825 |
# File 'lib/discordrb/data/server.rb', line 822 def webhooks webhooks = JSON.parse(API::Server.webhooks(@bot.token, @id)) webhooks.map { |webhook| Webhook.new(webhook, @bot) } end |
#widget_banner_url(style) ⇒ String?
Returns the widget banner URL to the server that displays the amount of online members,
server icon and server name in a stylish way. nil if the widget is not enabled.
348 349 350 351 352 353 |
# File 'lib/discordrb/data/server.rb', line 348 def (style) update_data if @widget_enabled.nil? return unless @widget_enabled API.(@id, style) end |
#widget_channel ⇒ Channel? Also known as: embed_channel
Returns the channel the server widget will make an invite for.
201 202 203 204 |
# File 'lib/discordrb/data/server.rb', line 201 def if @widget_enabled.nil? @bot.channel(@widget_channel_id) if @widget_channel_id end |
#widget_channel=(channel) ⇒ Object Also known as: embed_channel=
Changes the channel on the server's widget
224 225 226 |
# File 'lib/discordrb/data/server.rb', line 224 def (channel) (, channel) end |
#widget_enabled=(value) ⇒ Object Also known as: embed_enabled=
Sets whether this server's widget is enabled
209 210 211 |
# File 'lib/discordrb/data/server.rb', line 209 def (value) (value, ) end |
#widget_enabled? ⇒ true, false Also known as: widget?, embed_enabled, embed?
Returns whether or not the server has widget enabled.
192 193 194 195 |
# File 'lib/discordrb/data/server.rb', line 192 def if @widget_enabled.nil? @widget_enabled end |
#widget_url ⇒ String?
Returns the widget URL to the server that displays the amount of online members in a
stylish way. nil if the widget is not enabled.
333 334 335 336 337 338 |
# File 'lib/discordrb/data/server.rb', line 333 def update_data if @widget_enabled.nil? return unless @widget_enabled API.(@id) end |