Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Includes:
- IDObject, ServerAttributes
- Defined in:
- lib/discordrb/data/server.rb
Overview
An isolated collection of channels and member's 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
- MFA_LEVELS =
A map of possible multi-factor authentication levels to symbol names
{ none: 0, elevated: 1 }.freeze
- NSFW_LEVELS =
A map of possible NSFW levels to symbol names
{ default: 0, explicit: 1, safe: 2, age_restricted: 3 }.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.
-
#banner_id ⇒ String?
readonly
The hash of the server's banner image or GIF.
-
#boost_level ⇒ Integer
readonly
The server's Nitro boost level, 0 if no level.
-
#boost_progress_bar ⇒ true, false
(also: #boost_progress_bar?)
readonly
Whether or not the server has the boost progress bar enabled.
-
#booster_count ⇒ Integer
readonly
The server's amount of Nitro boosters, 0 if no one has boosted.
-
#channels ⇒ Array<Channel>
readonly
An array of all the channels (text and voice) on this server.
-
#description ⇒ String?
readonly
The description of the server.
-
#discovery_splash_id ⇒ String?
readonly
The hash of the server's discovery splash image.
-
#dm_spam_detected_at ⇒ Time?
readonly
The time at when DM spam was last detected on the server.
-
#dms_disabled_until ⇒ Time?
readonly
The time at when non-friend direct messages will be re-enabled on the 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").
-
#invites_disabled_until ⇒ Time?
readonly
The time at when invites will be re-enabled on the server.
-
#large ⇒ true, false
(also: #large?)
readonly
it means the members list may be inaccurate for a couple seconds after starting up the bot.
-
#locale ⇒ String
readonly
The preferred locale of the server.
-
#max_member_count ⇒ Integer
readonly
The maximum number of members that can join the server.
-
#max_presence_count ⇒ Integer?
readonly
The maximum number of members that can concurrently be online in the server.
-
#max_stage_video_channel_members ⇒ Integer
readonly
The maximum number of members that can concurrently watch a stream in a stage channel.
-
#max_video_channel_members ⇒ Integer
readonly
The maximum number of members that can concurrently watch a stream in a video channel.
-
#member_count ⇒ Integer
readonly
The absolute number of members on this server, offline or not.
-
#raid_detected_at ⇒ Time?
readonly
The time at when the last raid was detected on the server.
-
#region_id ⇒ String
readonly
The ID of the region the server is on (e.g.
amsterdam). -
#splash_id ⇒ String?
(also: #splash_hash)
readonly
The hash of the server's invite splash image.
-
#system_channel_flags ⇒ Integer
readonly
The flags for the server's designated system channel.
-
#vanity_invite_code ⇒ String?
readonly
The code of the server's custom vanity invite link.
-
#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?
Get the AFK channel of the server.
-
#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_url(format: 'webp') ⇒ String?
Utility method to get a server's banner URL.
-
#bans(limit: nil, before_id: nil, after_id: nil) ⇒ Array<ServerBan>
Retrieve banned users from this server.
-
#bans!(limit: 1000, before: nil, after: nil) ⇒ Array<ServerBan>
Get the users who have been banned from the 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.
-
#create_scheduled_event(name:, start_time:, entity_type:, end_time: nil, channel: nil, location: nil, description: nil, cover: nil, recurrence_rule: nil, reason: nil) {|builder| ... } ⇒ ScheduledEvent
Create a scheduled event on this server.
-
#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_messages = 'All messages', :only_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.
-
#discovery_splash_url(format: 'webp') ⇒ String?
Utility method to get a server's discovery splash URL.
-
#dm_spam_detected? ⇒ true, false
Check if the auto-moderation system has detected DM spam.
-
#dms_disabled? ⇒ true, false
Check if the server has disabled non-friend DMs.
-
#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 (:disabled = 'Don't scan any messages.', :members_without_roles = 'Scan messages for members without a role.', :all_members = '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.
-
#invites_disabled? ⇒ true, false
Check if the server has paused invites.
-
#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.
-
#mfa_level ⇒ Symbol
The multi-factor authentication level of the server (:none = 'no MFA/2FA requirement for moderation actions', :elevated = 'MFA/2FA is required for moderation actions').
-
#modify(name: :undef, verification_level: :undef, notification_level: :undef, explicit_content_filter: :undef, afk_channel: :undef, afk_timeout: :undef, icon: :undef, splash: :undef, discovery_splash: :undef, banner: :undef, system_channel: :undef, system_channel_flags: :undef, rules_channel: :undef, public_updates_channel: :undef, locale: :undef, features: :undef, description: :undef, boost_progress_bar: :undef, safety_alerts_channel: :undef, widget_enabled: :undef, widget_channel: :undef, dms_disabled_until: :undef, invites_disabled_until: :undef, reason: nil) ⇒ nil
Modify the properties of the server.
-
#modify_widget(enabled, channel, reason = nil) ⇒ Object
(also: #modify_embed)
deprecated
Deprecated.
Please migrate to using #modify with the
widget_enabled:andwidget_channel:parameters. -
#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.
-
#nsfw_level ⇒ Symbol
The NSFW level of the server (:default = 'no NSFW level has been set', :explicit = 'the server may contain explicit content', :safe = 'the server does not contain NSFW content', :age_restricted = 'server membership is restricted to adults').
-
#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.
-
#public_updates_channel ⇒ Channel?
Get the public updates channel of the server.
-
#raid_detected? ⇒ true, false
Check if the auto-moderation system has detected a raid.
-
#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.
-
#role_member_counts ⇒ Hash<Integer => Integer>
Get a mapping of role IDs to the amount of members who have the role.
-
#roles ⇒ Array<Role>
An array of all the roles available on this server.
-
#rules_channel ⇒ Channel?
Get the rules channel of the server.
-
#safety_alerts_channel ⇒ Channel?
Get the safety alerts channel of the server.
-
#scheduled_event(scheduled_event_id, request: true) ⇒ ScheduledEvent?
Get a specific scheduled event on the server.
-
#scheduled_events(bypass_cache: false) ⇒ Array<ScheduledEvent>
Get the scheduled events on the server.
-
#search_members(name:, limit: nil) ⇒ Array<Member>?
Searches a server for members that matches a username or a nickname.
-
#search_messages(limit: 25, offset: nil, before: nil, after: nil, content: nil, slop: 2, channels: nil, authors: nil, author_types: nil, mentions: nil, role_mentions: nil, mentions_everyone: nil, reply_users: nil, reply_messages: nil, pinned: nil, contains: nil, embed_types: nil, embed_providers: nil, link_hosts: nil, file_names: nil, file_extensions: nil, include_nsfw: true, sort_by: nil, sort_order: :descending) ⇒ SearchedMessages
Search the messages that have been sent in this server.
-
#set_widget_channel(channel, reason = nil) ⇒ Object
(also: #set_embed_channel)
deprecated
Deprecated.
Please migrate to using #modify with the
widget_channel:parameter. -
#set_widget_enabled(value, reason = nil) ⇒ Object
(also: #set_embed_enabled)
deprecated
Deprecated.
Please migrate to using #modify with the
widget_enabled:parameter. -
#splash_url(format: 'webp') ⇒ String?
Utility method to get a server's splash URL.
-
#system_channel ⇒ Channel?
Get the system channel of the server.
-
#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.
-
#vanity_invite_url ⇒ String?
(also: #vanity_invite_link)
Create an invite link using the server's vanity code.
-
#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=)
deprecated
Deprecated.
Please migrate to using #modify with the
widget_channel:parameter. -
#widget_enabled=(value) ⇒ Object
(also: #embed_enabled=)
deprecated
Deprecated.
Please migrate to using #modify with the
widget_enabled:parameter. -
#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.
48 49 50 |
# File 'lib/discordrb/data/server.rb', line 48 def afk_timeout @afk_timeout end |
#banner_id ⇒ String? (readonly)
Returns the hash of the server's banner image or GIF.
66 67 68 |
# File 'lib/discordrb/data/server.rb', line 66 def @banner_id end |
#boost_level ⇒ Integer (readonly)
Returns the server's Nitro boost level, 0 if no level.
57 58 59 |
# File 'lib/discordrb/data/server.rb', line 57 def boost_level @boost_level end |
#boost_progress_bar ⇒ true, false (readonly) Also known as: boost_progress_bar?
Returns whether or not the server has the boost progress bar enabled.
95 96 97 |
# File 'lib/discordrb/data/server.rb', line 95 def @boost_progress_bar end |
#booster_count ⇒ Integer (readonly)
Returns the server's amount of Nitro boosters, 0 if no one has boosted.
54 55 56 |
# File 'lib/discordrb/data/server.rb', line 54 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 |
#description ⇒ String? (readonly)
Returns the description of the server. Shown in server discovery and external embeds.
63 64 65 |
# File 'lib/discordrb/data/server.rb', line 63 def description @description end |
#discovery_splash_id ⇒ String? (readonly)
Returns the hash of the server's discovery splash image.
83 84 85 |
# File 'lib/discordrb/data/server.rb', line 83 def discovery_splash_id @discovery_splash_id end |
#dm_spam_detected_at ⇒ Time? (readonly)
Returns the time at when DM spam was last detected on the server.
102 103 104 |
# File 'lib/discordrb/data/server.rb', line 102 def dm_spam_detected_at @dm_spam_detected_at end |
#dms_disabled_until ⇒ Time? (readonly)
Returns the time at when non-friend direct messages will be re-enabled on the server.
108 109 110 |
# File 'lib/discordrb/data/server.rb', line 108 def dms_disabled_until @dms_disabled_until end |
#emoji ⇒ Hash<Integer => Emoji> (readonly) Also known as: emojis
Returns a hash of all the emoji available on this server.
33 34 35 |
# File 'lib/discordrb/data/server.rb', line 33 def emoji @emoji end |
#features ⇒ Array<Symbol> (readonly)
Returns the features of the server (eg. "INVITE_SPLASH").
42 43 44 |
# File 'lib/discordrb/data/server.rb', line 42 def features @features end |
#invites_disabled_until ⇒ Time? (readonly)
Returns the time at when invites will be re-enabled on the server.
105 106 107 |
# File 'lib/discordrb/data/server.rb', line 105 def invites_disabled_until @invites_disabled_until 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.
38 39 40 |
# File 'lib/discordrb/data/server.rb', line 38 def large @large end |
#locale ⇒ String (readonly)
Returns the preferred locale of the server. Used in server discovery and notices from Discord.
60 61 62 |
# File 'lib/discordrb/data/server.rb', line 60 def locale @locale end |
#max_member_count ⇒ Integer (readonly)
Returns the maximum number of members that can join the server.
73 74 75 |
# File 'lib/discordrb/data/server.rb', line 73 def max_member_count @max_member_count end |
#max_presence_count ⇒ Integer? (readonly)
Returns the maximum number of members that can concurrently be online in the server.
Always set to nil except for the largest of servers.
80 81 82 |
# File 'lib/discordrb/data/server.rb', line 80 def max_presence_count @max_presence_count end |
#max_stage_video_channel_members ⇒ Integer (readonly)
Returns the maximum number of members that can concurrently watch a stream in a stage channel.
92 93 94 |
# File 'lib/discordrb/data/server.rb', line 92 def max_stage_video_channel_members @max_stage_video_channel_members end |
#max_video_channel_members ⇒ Integer (readonly)
Returns the maximum number of members that can concurrently watch a stream in a video channel.
89 90 91 |
# File 'lib/discordrb/data/server.rb', line 89 def max_video_channel_members @max_video_channel_members end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
45 46 47 |
# File 'lib/discordrb/data/server.rb', line 45 def member_count @member_count end |
#raid_detected_at ⇒ Time? (readonly)
Returns the time at when the last raid was detected on the server.
99 100 101 |
# File 'lib/discordrb/data/server.rb', line 99 def raid_detected_at @raid_detected_at 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 |
#splash_id ⇒ String? (readonly) Also known as: splash_hash
Returns the hash of the server's invite splash image.
69 70 71 |
# File 'lib/discordrb/data/server.rb', line 69 def splash_id @splash_id end |
#system_channel_flags ⇒ Integer (readonly)
Returns the flags for the server's designated system channel.
86 87 88 |
# File 'lib/discordrb/data/server.rb', line 86 def system_channel_flags @system_channel_flags end |
#vanity_invite_code ⇒ String? (readonly)
Returns the code of the server's custom vanity invite link.
76 77 78 |
# File 'lib/discordrb/data/server.rb', line 76 def vanity_invite_code @vanity_invite_code end |
#voice_states ⇒ Hash<Integer => VoiceState> (readonly)
Returns the hash (user ID => voice state) of voice states of members on this server.
51 52 53 |
# File 'lib/discordrb/data/server.rb', line 51 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.
795 796 797 798 799 800 801 |
# File 'lib/discordrb/data/server.rb', line 795 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
344 345 346 347 348 349 350 351 |
# File 'lib/discordrb/data/server.rb', line 344 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?
Get the AFK channel of the server.
1216 1217 1218 |
# File 'lib/discordrb/data/server.rb', line 1216 def afk_channel @bot.channel(@afk_channel_id) if @afk_channel_id end |
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
983 984 985 |
# File 'lib/discordrb/data/server.rb', line 983 def afk_channel=(afk_channel) modify(afk_channel: afk_channel) end |
#any_emoji? ⇒ true, false Also known as: has_emoji?, emoji?
Returns whether this server has any emoji or not.
1083 1084 1085 |
# File 'lib/discordrb/data/server.rb', line 1083 def any_emoji? @emoji.any? end |
#audit_logs(action: nil, user: nil, limit: 50, before: nil) ⇒ AuditLogs
Returns The server's audit logs.
238 239 240 241 242 243 244 245 |
# File 'lib/discordrb/data/server.rb', line 238 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.
954 955 956 957 958 959 960 961 |
# File 'lib/discordrb/data/server.rb', line 954 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.
896 897 898 899 900 901 902 903 904 |
# File 'lib/discordrb/data/server.rb', line 896 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_url(format: 'webp') ⇒ String?
Utility method to get a server's banner URL.
437 438 439 |
# File 'lib/discordrb/data/server.rb', line 437 def (format: 'webp') API.(@id, @banner_id, format) if @banner_id end |
#bans(limit: nil, before_id: nil, after_id: nil) ⇒ Array<ServerBan>
Retrieve banned users from this server.
854 855 856 857 858 859 |
# File 'lib/discordrb/data/server.rb', line 854 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, @bot.ensure_user(e['user']), e['reason']) end end |
#bans!(limit: 1000, before: nil, after: nil) ⇒ Array<ServerBan>
When using the before parameter, bans will be sorted in descending order by user ID
(newest users first), and in ascending order by user ID (oldest users first) otherwise.
Get the users who have been banned from the server.
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/discordrb/data/server.rb', line 868 def bans!(limit: 1000, before: nil, after: nil) raise ArgumentError, "'before' and 'after' are mutually exclusive" if before && after f_limit = limit && limit <= 1000 ? limit : 1000 f_after = after.is_a?(Time) ? IDObject.synthesize(after) : after&.resolve_id f_before = before.is_a?(Time) ? IDObject.synthesize(before) : before&.resolve_id get_bans = lambda do |before: nil, after: nil| data = API::Server.bans(@bot.token, @id, f_limit, before&.id || f_before, after&.id || f_after) JSON.parse(data).map { |ban| ServerBan.new(self, @bot.ensure_user(ban['user']), ban['reason']) } end paginator = Paginator.new(limit, before ? :up : :down) do |page| if before get_bans.call(before: page&.first&.user) else get_bans.call(after: page&.last&.user) end end paginator.to_a end |
#begin_prune(days, reason = nil) ⇒ Integer Also known as: prune
Prunes (kicks) an amount of members for inactivity
369 370 371 372 373 374 |
# File 'lib/discordrb/data/server.rb', line 369 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.
222 223 224 |
# File 'lib/discordrb/data/server.rb', line 222 def bot member(@bot.profile) end |
#bot_members ⇒ Array<Member>
Returns an array of all the bot members on this server.
212 213 214 |
# File 'lib/discordrb/data/server.rb', line 212 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.
918 919 920 921 922 923 924 925 |
# File 'lib/discordrb/data/server.rb', line 918 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.
389 390 391 |
# File 'lib/discordrb/data/server.rb', line 389 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.
733 734 735 736 737 738 739 740 741 |
# File 'lib/discordrb/data/server.rb', line 733 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.
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
# File 'lib/discordrb/data/server.rb', line 758 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.id] = role end |
#create_scheduled_event(name:, start_time:, entity_type:, end_time: nil, channel: nil, location: nil, description: nil, cover: nil, recurrence_rule: nil, reason: nil) {|builder| ... } ⇒ ScheduledEvent
Create a scheduled event on this server.
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'lib/discordrb/data/server.rb', line 1178 def create_scheduled_event(name:, start_time:, entity_type:, end_time: nil, channel: nil, location: nil, description: nil, cover: nil, recurrence_rule: nil, reason: nil) yield((builder = ScheduledEvent::RecurrenceRule::Builder.new)) if block_given? = { name: name, privacy_level: 2, scheduled_start_time: start_time&.iso8601, entity_type: ScheduledEvent::ENTITY_TYPES[entity_type] || entity_type, channel_id: channel&.resolve_id, entity_metadata: location ? { location: location } : nil, scheduled_end_time: end_time&.iso8601, description: description, image: cover.respond_to?(:read) ? Discordrb.encode64(cover) : cover, recurrence_rule: block_given? ? builder.to_h : recurrence_rule&.to_h } event = JSON.parse(API::Server.create_scheduled_event(@bot.token, @id, **, reason: reason)) scheduled_event = ScheduledEvent.new(event, self, @bot) @scheduled_events[scheduled_event.id] = scheduled_event 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.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/discordrb/data/server.rb', line 136 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_messages = 'All messages', :only_mentions = 'Only @mentions').
1026 1027 1028 |
# File 'lib/discordrb/data/server.rb', line 1026 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
1032 1033 1034 |
# File 'lib/discordrb/data/server.rb', line 1032 def (notification_level) modify(notification_level: notification_level) end |
#delete_emoji(emoji, reason: nil) ⇒ Object
Delete a custom emoji on this server
806 807 808 |
# File 'lib/discordrb/data/server.rb', line 806 def delete_emoji(emoji, reason: nil) API::Server.delete_emoji(@bot.token, @id, emoji.resolve_id, reason) end |
#discovery_splash_url(format: 'webp') ⇒ String?
Utility method to get a server's discovery splash URL.
444 445 446 |
# File 'lib/discordrb/data/server.rb', line 444 def discovery_splash_url(format: 'webp') API.discovery_splash_url(@id, @discovery_splash_id, format) if @discovery_splash_id end |
#dm_spam_detected? ⇒ true, false
Check if the auto-moderation system has detected DM spam.
1108 1109 1110 |
# File 'lib/discordrb/data/server.rb', line 1108 def dm_spam_detected? !@dm_spam_detected_at.nil? end |
#dms_disabled? ⇒ true, false
Check if the server has disabled non-friend DMs.
1114 1115 1116 |
# File 'lib/discordrb/data/server.rb', line 1114 def dms_disabled? !@dms_disabled_until.nil? && @dms_disabled_until > Time.now end |
#edit_emoji(emoji, name: nil, roles: nil, reason: nil) ⇒ Emoji
Changes the name and/or role whitelist of an emoji on this server.
816 817 818 819 820 821 |
# File 'lib/discordrb/data/server.rb', line 816 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.
150 151 152 |
# File 'lib/discordrb/data/server.rb', line 150 def everyone_role @roles[@id] end |
#explicit_content_filter ⇒ Symbol Also known as: content_filter_level
Returns The explicit content filter level of the server (:disabled = 'Don't scan any messages.', :members_without_roles = 'Scan messages for members without a role.', :all_members = 'Scan messages sent by all members.').
1046 1047 1048 |
# File 'lib/discordrb/data/server.rb', line 1046 def explicit_content_filter FILTER_LEVELS.key(@explicit_content_filter) end |
#explicit_content_filter=(filter_level) ⇒ Object
Sets the server content filter.
1054 1055 1056 |
# File 'lib/discordrb/data/server.rb', line 1054 def explicit_content_filter=(filter_level) modify(explicit_content_filter: filter_level) end |
#icon=(icon) ⇒ Object
Sets the server's icon.
977 978 979 |
# File 'lib/discordrb/data/server.rb', line 977 def icon=(icon) modify(icon: icon) end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
1421 1422 1423 |
# File 'lib/discordrb/data/server.rb', line 1421 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.
228 229 230 231 |
# File 'lib/discordrb/data/server.rb', line 228 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.
1134 1135 1136 1137 |
# File 'lib/discordrb/data/server.rb', line 1134 def invites invites = JSON.parse(API::Server.invites(@bot.token, @id)) invites.map { |invite| Invite.new(invite, @bot) } end |
#invites_disabled? ⇒ true, false
Check if the server has paused invites.
1121 1122 1123 |
# File 'lib/discordrb/data/server.rb', line 1121 def invites_disabled? (!@invites_disabled_until.nil? && @invites_disabled_until > Time.now) || @features.include?(:invites_disabled) end |
#kick(user, reason = nil) ⇒ Object
Kicks a user from this server.
930 931 932 |
# File 'lib/discordrb/data/server.rb', line 930 def kick(user, reason = nil) API::Server.remove_member(@bot.token, @id, user.resolve_id, reason) end |
#leave ⇒ Object
Leave the server.
943 944 945 |
# File 'lib/discordrb/data/server.rb', line 943 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.
449 450 451 |
# File 'lib/discordrb/data/server.rb', line 449 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.
825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'lib/discordrb/data/server.rb', line 825 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
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/discordrb/data/server.rb', line 183 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.
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/discordrb/data/server.rb', line 196 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 |
#mfa_level ⇒ Symbol
Returns The multi-factor authentication level of the server (:none = 'no MFA/2FA requirement for moderation actions', :elevated = 'MFA/2FA is required for moderation actions').
1065 1066 1067 |
# File 'lib/discordrb/data/server.rb', line 1065 def mfa_level MFA_LEVELS.key @mfa_level end |
#modify(name: :undef, verification_level: :undef, notification_level: :undef, explicit_content_filter: :undef, afk_channel: :undef, afk_timeout: :undef, icon: :undef, splash: :undef, discovery_splash: :undef, banner: :undef, system_channel: :undef, system_channel_flags: :undef, rules_channel: :undef, public_updates_channel: :undef, locale: :undef, features: :undef, description: :undef, boost_progress_bar: :undef, safety_alerts_channel: :undef, widget_enabled: :undef, widget_channel: :undef, dms_disabled_until: :undef, invites_disabled_until: :undef, reason: nil) ⇒ nil
Modify the properties of the server.
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
# File 'lib/discordrb/data/server.rb', line 1270 def modify( name: :undef, verification_level: :undef, notification_level: :undef, explicit_content_filter: :undef, afk_channel: :undef, afk_timeout: :undef, icon: :undef, splash: :undef, discovery_splash: :undef, banner: :undef, system_channel: :undef, system_channel_flags: :undef, rules_channel: :undef, public_updates_channel: :undef, locale: :undef, features: :undef, description: :undef, boost_progress_bar: :undef, safety_alerts_channel: :undef, widget_enabled: :undef, widget_channel: :undef, dms_disabled_until: :undef, invites_disabled_until: :undef, reason: nil ) data = { name: name, verification_level: VERIFICATION_LEVELS[verification_level] || verification_level, default_message_notifications: NOTIFICATION_LEVELS[notification_level] || notification_level, explicit_content_filter: FILTER_LEVELS[explicit_content_filter] || explicit_content_filter, afk_channel_id: afk_channel == :undef ? afk_channel : afk_channel&.resolve_id, afk_timeout: afk_timeout, icon: icon.respond_to?(:read) ? Discordrb.encode64(icon) : icon, splash: splash.respond_to?(:read) ? Discordrb.encode64(splash) : splash, discovery_splash: discovery_splash.respond_to?(:read) ? Discordrb.encode64(discovery_splash) : discovery_splash, banner: .respond_to?(:read) ? Discordrb.encode64() : , system_channel_id: system_channel == :undef ? system_channel : system_channel&.resolve_id, system_channel_flags: system_channel_flags, rules_channel_id: rules_channel == :undef ? rules_channel : rules_channel&.resolve_id, public_updates_channel_id: public_updates_channel == :undef ? public_updates_channel : public_updates_channel&.resolve_id, preferred_locale: locale, features: features == :undef ? features : features.map(&:upcase), description: description, premium_progress_bar_enabled: , safety_alerts_channel_id: safety_alerts_channel == :undef ? safety_alerts_channel : safety_alerts_channel&.resolve_id } if != :undef || != :undef = { enabled: , channel_id: == :undef ? : &.resolve_id } (JSON.parse(API::Server.(@bot.token, @id, **, reason: reason))) end if invites_disabled_until != :undef || dms_disabled_until != :undef incidents_data = { dms_disabled_until: dms_disabled_until == :undef ? @dms_disabled_until&.iso8601 : dms_disabled_until&.iso8601, invites_disabled_until: invites_disabled_until == :undef ? @invites_disabled_until&.iso8601 : invites_disabled_until&.iso8601 } process_incident_actions(JSON.parse(API::Server.update_incident_actions(@bot.token, @id, **incidents_data, reason: reason))) end return unless data.any? { |_, value| value != :undef } update_data(JSON.parse(API::Server.update!(@bot.token, @id, **data, reason: reason))) nil end |
#modify_widget(enabled, channel, reason = nil) ⇒ Object Also known as: modify_embed
Please migrate to using #modify with the widget_enabled: and widget_channel: parameters.
Changes the channel on the server's widget, and sets whether it is enabled.
315 316 317 318 319 |
# File 'lib/discordrb/data/server.rb', line 315 def (enabled, channel, reason = nil) if @widget_enabled.nil? channel_id = channel ? channel.resolve_id : @widget_channel_id (JSON.parse(API::Server.(@bot.token, @id, enabled, channel_id, reason))) 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.
938 939 940 |
# File 'lib/discordrb/data/server.rb', line 938 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.
949 950 951 |
# File 'lib/discordrb/data/server.rb', line 949 def name=(name) modify(name: name) end |
#non_bot_members ⇒ Array<Member>
Returns an array of all the non bot members on this server.
217 218 219 |
# File 'lib/discordrb/data/server.rb', line 217 def non_bot_members members.reject(&:bot_account?) end |
#nsfw_level ⇒ Symbol
Returns The NSFW level of the server (:default = 'no NSFW level has been set', :explicit = 'the server may contain explicit content', :safe = 'the server does not contain NSFW content', :age_restricted = 'server membership is restricted to adults').
1078 1079 1080 |
# File 'lib/discordrb/data/server.rb', line 1078 def nsfw_level NSFW_LEVELS.key @nsfw_level 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.
325 326 327 328 329 |
# File 'lib/discordrb/data/server.rb', line 325 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.
394 395 396 |
# File 'lib/discordrb/data/server.rb', line 394 def orphan_channels @channels.reject { |c| c.parent || c.category? } end |
#owner ⇒ Member
Returns The server owner.
128 129 130 |
# File 'lib/discordrb/data/server.rb', line 128 def owner member(@owner_id) end |
#preview ⇒ ServerPreview
Returns the preview of this server shown in the discovery page.
399 400 401 |
# File 'lib/discordrb/data/server.rb', line 399 def preview @bot.server_preview(@id) end |
#prune_count(days) ⇒ Integer
Returns the amount of members that are candidates for pruning
357 358 359 360 361 362 |
# File 'lib/discordrb/data/server.rb', line 357 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 |
#public_updates_channel ⇒ Channel?
Get the public updates channel of the server.
1240 1241 1242 |
# File 'lib/discordrb/data/server.rb', line 1240 def public_updates_channel @bot.channel(@public_updates_channel_id) if @public_updates_channel_id end |
#raid_detected? ⇒ true, false
Check if the auto-moderation system has detected a raid.
1102 1103 1104 |
# File 'lib/discordrb/data/server.rb', line 1102 def raid_detected? !@raid_detected_at.nil? end |
#region ⇒ VoiceRegion?
This may return nil if this server's voice region is deprecated.
Returns voice region data for this server's region.
965 966 967 |
# File 'lib/discordrb/data/server.rb', line 965 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.
971 972 973 |
# File 'lib/discordrb/data/server.rb', line 971 def region=(region) update_data(JSON.parse(API::Server.update!(@bot.token, @id, region: region.to_s))) end |
#role(id) ⇒ Role?
Gets a role on this server based on its ID.
162 163 164 |
# File 'lib/discordrb/data/server.rb', line 162 def role(id) @roles[id.resolve_id] end |
#role_member_counts ⇒ Hash<Integer => Integer>
Get a mapping of role IDs to the amount of members who have the role.
174 175 176 177 178 |
# File 'lib/discordrb/data/server.rb', line 174 def role_member_counts response = JSON.parse(API::Server.role_member_counts(@bot.token, @id)) response.transform_keys!(&:to_i) response.tap { |hash| hash[@id] = @member_count } end |
#roles ⇒ Array<Role>
Returns an array of all the roles available on this server.
155 156 157 |
# File 'lib/discordrb/data/server.rb', line 155 def roles @roles.values end |
#rules_channel ⇒ Channel?
Get the rules channel of the server.
1222 1223 1224 |
# File 'lib/discordrb/data/server.rb', line 1222 def rules_channel @bot.channel(@rules_channel_id) if @rules_channel_id end |
#safety_alerts_channel ⇒ Channel?
Get the safety alerts channel of the server.
1234 1235 1236 |
# File 'lib/discordrb/data/server.rb', line 1234 def safety_alerts_channel @bot.channel(@safety_alerts_channel_id) if @safety_alerts_channel_id end |
#scheduled_event(scheduled_event_id, request: true) ⇒ ScheduledEvent?
Get a specific scheduled event on the server.
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 |
# File 'lib/discordrb/data/server.rb', line 1153 def scheduled_event(scheduled_event_id, request: true) id = scheduled_event_id.resolve_id return @scheduled_events[id] if @scheduled_events[id] return nil unless request event = JSON.parse(API::Server.get_scheduled_event(@bot.token, @id, id, with_user_count: true)) scheduled_event = ScheduledEvent.new(event, self, @bot) @scheduled_events[scheduled_event.id] = scheduled_event rescue StandardError nil end |
#scheduled_events(bypass_cache: false) ⇒ Array<ScheduledEvent>
Get the scheduled events on the server.
1143 1144 1145 1146 1147 |
# File 'lib/discordrb/data/server.rb', line 1143 def scheduled_events(bypass_cache: false) process_scheduled_events(JSON.parse(API::Server.list_scheduled_events(@bot.token, @id, with_user_count: true))) if bypass_cache @scheduled_events.values end |
#search_members(name:, limit: nil) ⇒ Array<Member>?
Searches a server for members that matches a username or a nickname.
842 843 844 845 846 847 |
# File 'lib/discordrb/data/server.rb', line 842 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 |
#search_messages(limit: 25, offset: nil, before: nil, after: nil, content: nil, slop: 2, channels: nil, authors: nil, author_types: nil, mentions: nil, role_mentions: nil, mentions_everyone: nil, reply_users: nil, reply_messages: nil, pinned: nil, contains: nil, embed_types: nil, embed_providers: nil, link_hosts: nil, file_names: nil, file_extensions: nil, include_nsfw: true, sort_by: nil, sort_order: :descending) ⇒ SearchedMessages
Messages with GIFs sent before February 24th, 2026 may not be returned under the gif embed type when using the embed_types: parameter.
Messages fetched via this method will not contain reactions. This means that Message#reactions will always return an empty array, even if the message has reactions.
Search the messages that have been sent in this server.
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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/discordrb/data/server.rb', line 527 def ( limit: 25, offset: nil, before: nil, after: nil, content: nil, slop: 2, channels: nil, authors: nil, author_types: nil, mentions: nil, role_mentions: nil, mentions_everyone: nil, reply_users: nil, reply_messages: nil, pinned: nil, contains: nil, embed_types: nil, embed_providers: nil, link_hosts: nil, file_names: nil, file_extensions: nil, include_nsfw: true, sort_by: nil, sort_order: :descending ) sort_order = case sort_order&.to_sym when nil, :desc, :descending, :newest_first :desc when :asc, :ascending, :oldest_first :asc else raise ArgumentError, "Invalid value for the 'sort_order' parameter" end sort_by = case sort_by&.to_sym when nil, :timestamp, :creation_time :timestamp when :relevance, :match_score :relevance else raise ArgumentError, "Invalid value for the 'sort_by' parameter" end = { limit: limit && limit <= 25 ? limit : 25, max_id: before.is_a?(Time) ? IDObject.synthesise(before) : before&.resolve_id, min_id: after.is_a?(Time) ? IDObject.synthesise(after) : after&.resolve_id, offset: offset || 0, slop: slop, content: content&.to_s, channel_id: channels ? Array(channels).map(&:resolve_id) : channels, author_type: ? Array() : , author_id: ? Array().map(&:resolve_id) : , mentions: mentions ? Array(mentions).map(&:resolve_id) : mentions, mentions_role_id: role_mentions ? Array(role_mentions).map(&:resolve_id) : role_mentions, mention_everyone: mentions_everyone, replied_to_user_id: reply_users ? Array(reply_users).map(&:resolve_id) : reply_users, replied_to_message_id: ? Array().map(&:resolve_id) : , pinned: pinned, has: contains ? Array(contains) : contains, embed_type: ? Array() : , embed_provider: ? Array() : , link_hostname: link_hosts ? Array(link_hosts) : link_hosts, attachment_filename: (Array(file_names).map { |file| file.is_a?(Attachment) ? file.filename : file } if file_names), attachment_extension: file_extensions ? Array(file_extensions).map { |type| type.to_s.delete_prefix('.') } : file_extensions, sort_by: sort_by, sort_order: sort_order, include_nsfw: include_nsfw }.compact raise ArgumentError, "The 'role_mentions' parameter cannot contain the everyone role" if [:mentions_role_id]&.any?(@id) # Only store the total message count from the first request. total = nil = lambda do |query| data = JSON.parse(API::Server.(@bot.token, @id, **, **query.compact)) total ||= data['total_results'] data['threads']&.each do |thread| thread['member'] = data['members']&.find { |member| thread['id'] == member['id'] } @bot.ensure_channel(thread, self) end data['messages'].collect { || Message.new([0], @bot) } end paginator = Paginator.new(limit, :down) do |page| if sort_by == :relevance if (count = (paginator.amount_fetched + [:offset])) > 9975 [] else .call(offset: count) end elsif sort_order == :desc .call(max_id: page&.last&.id, offset: page ? 0 : nil) else .call(min_id: page&.last&.id, offset: page ? 0 : nil) end end SearchedMessages.new(paginator.to_a, total, @bot) end |
#set_widget_channel(channel, reason = nil) ⇒ Object Also known as: set_embed_channel
Please migrate to using #modify with the widget_channel: parameter.
Changes the channel on the server's widget
305 306 307 |
# File 'lib/discordrb/data/server.rb', line 305 def (channel, reason = nil) (, channel, reason) end |
#set_widget_enabled(value, reason = nil) ⇒ Object Also known as: set_embed_enabled
Please migrate to using #modify with the widget_enabled: parameter.
Sets whether this server's widget is enabled
288 289 290 |
# File 'lib/discordrb/data/server.rb', line 288 def (value, reason = nil) (value, , reason) end |
#splash_url(format: 'webp') ⇒ String?
Utility method to get a server's splash URL.
429 430 431 |
# File 'lib/discordrb/data/server.rb', line 429 def splash_url(format: 'webp') API.splash_url(@id, @splash_id, format) if @splash_id end |
#system_channel ⇒ Channel?
Get the system channel of the server.
1228 1229 1230 |
# File 'lib/discordrb/data/server.rb', line 1228 def system_channel @bot.channel(@system_channel_id) if @system_channel_id end |
#system_channel=(system_channel) ⇒ Object
Sets the server's system channel.
989 990 991 |
# File 'lib/discordrb/data/server.rb', line 989 def system_channel=(system_channel) modify(system_channel: system_channel) end |
#text_channels ⇒ Array<Channel>
Returns an array of text channels on this server.
379 380 381 |
# File 'lib/discordrb/data/server.rb', line 379 def text_channels @channels.select(&:text?) end |
#unban(user, reason = nil) ⇒ Object
Unbans a previously banned user from this server.
909 910 911 |
# File 'lib/discordrb/data/server.rb', line 909 def unban(user, reason = nil) API::Server.unban_user(@bot.token, @id, user.resolve_id, reason) end |
#vanity_invite_url ⇒ String? Also known as: vanity_invite_link
Create an invite link using the server's vanity code.
1092 1093 1094 1095 1096 |
# File 'lib/discordrb/data/server.rb', line 1092 def vanity_invite_url return unless @vanity_invite_code "https://discord.gg/#{@vanity_invite_code}" 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').
1009 1010 1011 |
# File 'lib/discordrb/data/server.rb', line 1009 def verification_level VERIFICATION_LEVELS.key(@verification_level) end |
#verification_level=(level) ⇒ Object
Sets the verification level of the server
1015 1016 1017 |
# File 'lib/discordrb/data/server.rb', line 1015 def verification_level=(level) modify(verification_level: level) end |
#voice_channels ⇒ Array<Channel>
Returns an array of voice channels on this server.
384 385 386 |
# File 'lib/discordrb/data/server.rb', line 384 def voice_channels @channels.select(&:voice?) end |
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the server.
1127 1128 1129 1130 |
# File 'lib/discordrb/data/server.rb', line 1127 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.
419 420 421 422 423 |
# File 'lib/discordrb/data/server.rb', line 419 def (style) update_data if @widget_enabled.nil? API.(@id, style) if @widget_enabled end |
#widget_channel ⇒ Channel? Also known as: embed_channel
Returns the channel the server widget will make an invite for.
270 271 272 273 |
# File 'lib/discordrb/data/server.rb', line 270 def if @widget_enabled.nil? @bot.channel(@widget_channel_id) if @widget_channel_id end |
#widget_channel=(channel) ⇒ Object Also known as: embed_channel=
Please migrate to using #modify with the widget_channel: parameter.
Changes the channel on the server's widget
296 297 298 |
# File 'lib/discordrb/data/server.rb', line 296 def (channel) (, channel) end |
#widget_enabled=(value) ⇒ Object Also known as: embed_enabled=
Please migrate to using #modify with the widget_enabled: parameter.
Sets whether this server's widget is enabled
279 280 281 |
# File 'lib/discordrb/data/server.rb', line 279 def (value) (value, ) end |
#widget_enabled? ⇒ true, false Also known as: widget?, embed_enabled, embed?
Returns whether or not the server has widget enabled.
261 262 263 264 |
# File 'lib/discordrb/data/server.rb', line 261 def if @widget_enabled.nil? @widget_enabled end |