Class: OnyxCord::Server
- Inherits:
-
Object
- Object
- OnyxCord::Server
- Includes:
- IDObject, ServerAttributes
- Defined in:
- lib/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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/onyxcord/models/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.
806 807 808 809 810 811 812 |
# File 'lib/onyxcord/models/server.rb', line 806 def add_emoji(name, image, roles = [], reason: nil) image = image.respond_to?(:read) ? OnyxCord.encode64(image) : image data = OnyxCord::Internal::JSON.parse(REST::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
352 353 354 355 356 357 358 359 |
# File 'lib/onyxcord/models/server.rb', line 352 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 = REST::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute) return nil if response.empty? add_member Member.new(OnyxCord::Internal::JSON.parse(response), self, @bot) end |
#afk_channel ⇒ Channel?
Get the AFK channel of the server.
1230 1231 1232 |
# File 'lib/onyxcord/models/server.rb', line 1230 def afk_channel @bot.channel(@afk_channel_id) if @afk_channel_id end |
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
994 995 996 |
# File 'lib/onyxcord/models/server.rb', line 994 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.
1094 1095 1096 |
# File 'lib/onyxcord/models/server.rb', line 1094 def any_emoji? @emoji.any? end |
#audit_logs(action: nil, user: nil, limit: 50, before: nil) ⇒ AuditLogs
Returns The server's audit logs.
246 247 248 249 250 251 252 253 |
# File 'lib/onyxcord/models/server.rb', line 246 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, OnyxCord::Internal::JSON.parse(REST::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.
965 966 967 968 969 970 971 972 |
# File 'lib/onyxcord/models/server.rb', line 965 def available_voice_regions return @available_voice_regions if @available_voice_regions @available_voice_regions = {} data = OnyxCord::Internal::JSON.parse REST::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.
907 908 909 910 911 912 913 914 915 |
# File 'lib/onyxcord/models/server.rb', line 907 def ban(user, = 0, message_seconds: nil, reason: nil) = if != 0 && * 86_400 else || 0 end REST::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.
445 446 447 |
# File 'lib/onyxcord/models/server.rb', line 445 def (format: 'webp') REST.(@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.
865 866 867 868 869 870 |
# File 'lib/onyxcord/models/server.rb', line 865 def bans(limit: nil, before_id: nil, after_id: nil) response = OnyxCord::Internal::JSON.parse(REST::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.
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/onyxcord/models/server.rb', line 879 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 = REST::Server.bans(@bot.token, @id, f_limit, before&.id || f_before, after&.id || f_after) OnyxCord::Internal::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
377 378 379 380 381 382 |
# File 'lib/onyxcord/models/server.rb', line 377 def begin_prune(days, reason = nil) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = OnyxCord::Internal::JSON.parse REST::Server.begin_prune(@bot.token, @id, days, reason) response['pruned'] end |
#bot ⇒ Member
Returns the bot's own Member on this server.
230 231 232 |
# File 'lib/onyxcord/models/server.rb', line 230 def bot member(@bot.profile) end |
#bot_members ⇒ Array<Member>
Returns an array of all the bot members on this server.
220 221 222 |
# File 'lib/onyxcord/models/server.rb', line 220 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.
929 930 931 932 933 934 935 936 |
# File 'lib/onyxcord/models/server.rb', line 929 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 = REST::Server.bulk_ban(@bot.token, @id, users.map(&:resolve_id), , reason) BulkBan.new(OnyxCord::Internal::JSON.parse(response), self, reason) end |
#categories ⇒ Array<Channel>
Returns an array of category channels on this server.
397 398 399 |
# File 'lib/onyxcord/models/server.rb', line 397 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.
744 745 746 747 748 749 750 751 752 |
# File 'lib/onyxcord/models/server.rb', line 744 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 = REST::Server.create_channel(@bot.token, @id, name, type, topic, bitrate, user_limit, , parent_id, nsfw, rate_limit_per_user, position, reason) Channel.new(OnyxCord::Internal::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.
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/onyxcord/models/server.rb', line 769 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) ? OnyxCord.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 = OnyxCord.encode64(display_icon) end response = REST::Server.create_role(@bot.token, @id, name, nil, hoist, mentionable, &.to_s, reason, colours, icon, unicode_emoji) role = Role.new(OnyxCord::Internal::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.
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/onyxcord/models/server.rb', line 1189 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) ? OnyxCord.encode64(cover) : cover, recurrence_rule: block_given? ? builder.to_h : recurrence_rule&.to_h } event = OnyxCord::Internal::JSON.parse(REST::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.
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/onyxcord/models/server.rb', line 138 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').
1037 1038 1039 |
# File 'lib/onyxcord/models/server.rb', line 1037 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
1043 1044 1045 |
# File 'lib/onyxcord/models/server.rb', line 1043 def (notification_level) modify(notification_level: notification_level) end |
#delete_emoji(emoji, reason: nil) ⇒ Object
Delete a custom emoji on this server
817 818 819 |
# File 'lib/onyxcord/models/server.rb', line 817 def delete_emoji(emoji, reason: nil) REST::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.
452 453 454 |
# File 'lib/onyxcord/models/server.rb', line 452 def discovery_splash_url(format: 'webp') REST.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.
1119 1120 1121 |
# File 'lib/onyxcord/models/server.rb', line 1119 def dm_spam_detected? !@dm_spam_detected_at.nil? end |
#dms_disabled? ⇒ true, false
Check if the server has disabled non-friend DMs.
1125 1126 1127 |
# File 'lib/onyxcord/models/server.rb', line 1125 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.
827 828 829 830 831 832 |
# File 'lib/onyxcord/models/server.rb', line 827 def edit_emoji(emoji, name: nil, roles: nil, reason: nil) emoji = @emoji[emoji.resolve_id] data = OnyxCord::Internal::JSON.parse(REST::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.
152 153 154 |
# File 'lib/onyxcord/models/server.rb', line 152 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.').
1057 1058 1059 |
# File 'lib/onyxcord/models/server.rb', line 1057 def explicit_content_filter FILTER_LEVELS.key(@explicit_content_filter) end |
#explicit_content_filter=(filter_level) ⇒ Object
Sets the server content filter.
1065 1066 1067 |
# File 'lib/onyxcord/models/server.rb', line 1065 def explicit_content_filter=(filter_level) modify(explicit_content_filter: filter_level) end |
#icon=(icon) ⇒ Object
Sets the server's icon.
988 989 990 |
# File 'lib/onyxcord/models/server.rb', line 988 def icon=(icon) modify(icon: icon) end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
1435 1436 1437 |
# File 'lib/onyxcord/models/server.rb', line 1435 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.
236 237 238 239 |
# File 'lib/onyxcord/models/server.rb', line 236 def integrations integration = OnyxCord::Internal::JSON.parse(REST::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.
1145 1146 1147 1148 |
# File 'lib/onyxcord/models/server.rb', line 1145 def invites invites = OnyxCord::Internal::JSON.parse(REST::Server.invites(@bot.token, @id)) invites.map { |invite| Invite.new(invite, @bot) } end |
#invites_disabled? ⇒ true, false
Check if the server has paused invites.
1132 1133 1134 |
# File 'lib/onyxcord/models/server.rb', line 1132 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.
941 942 943 |
# File 'lib/onyxcord/models/server.rb', line 941 def kick(user, reason = nil) REST::Server.remove_member(@bot.token, @id, user.resolve_id, reason) end |
#leave ⇒ Object
Leave the server.
954 955 956 |
# File 'lib/onyxcord/models/server.rb', line 954 def leave REST::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.
457 458 459 |
# File 'lib/onyxcord/models/server.rb', line 457 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.
836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'lib/onyxcord/models/server.rb', line 836 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
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/onyxcord/models/server.rb', line 185 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.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/onyxcord/models/server.rb', line 198 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) @chunk_mutex.synchronize do @chunk_condition.wait(@chunk_mutex, 30) unless @chunked end raise Timeout::Error, "Guild members not received for server #{@id} within 30s" unless @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').
1076 1077 1078 |
# File 'lib/onyxcord/models/server.rb', line 1076 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.
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 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 |
# File 'lib/onyxcord/models/server.rb', line 1284 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) ? OnyxCord.encode64(icon) : icon, splash: splash.respond_to?(:read) ? OnyxCord.encode64(splash) : splash, discovery_splash: discovery_splash.respond_to?(:read) ? OnyxCord.encode64(discovery_splash) : discovery_splash, banner: .respond_to?(:read) ? OnyxCord.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 } (OnyxCord::Internal::JSON.parse(REST::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(OnyxCord::Internal::JSON.parse(REST::Server.update_incident_actions(@bot.token, @id, **incidents_data, reason: reason))) end return unless data.any? { |_, value| value != :undef } update_data(OnyxCord::Internal::JSON.parse(REST::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.
323 324 325 326 327 |
# File 'lib/onyxcord/models/server.rb', line 323 def (enabled, channel, reason = nil) if @widget_enabled.nil? channel_id = channel ? channel.resolve_id : @widget_channel_id (OnyxCord::Internal::JSON.parse(REST::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.
949 950 951 |
# File 'lib/onyxcord/models/server.rb', line 949 def move(user, channel) REST::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel&.resolve_id) end |
#name=(name) ⇒ Object
Sets the server's name.
960 961 962 |
# File 'lib/onyxcord/models/server.rb', line 960 def name=(name) modify(name: name) end |
#non_bot_members ⇒ Array<Member>
Returns an array of all the non bot members on this server.
225 226 227 |
# File 'lib/onyxcord/models/server.rb', line 225 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').
1089 1090 1091 |
# File 'lib/onyxcord/models/server.rb', line 1089 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.
333 334 335 336 337 |
# File 'lib/onyxcord/models/server.rb', line 333 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.
402 403 404 |
# File 'lib/onyxcord/models/server.rb', line 402 def orphan_channels @channels.reject { |c| c.parent || c.category? } end |
#owner ⇒ Member
Returns The server owner.
130 131 132 |
# File 'lib/onyxcord/models/server.rb', line 130 def owner member(@owner_id) end |
#preview ⇒ ServerPreview
Returns the preview of this server shown in the discovery page.
407 408 409 |
# File 'lib/onyxcord/models/server.rb', line 407 def preview @bot.server_preview(@id) end |
#prune_count(days) ⇒ Integer
Returns the amount of members that are candidates for pruning
365 366 367 368 369 370 |
# File 'lib/onyxcord/models/server.rb', line 365 def prune_count(days) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = OnyxCord::Internal::JSON.parse REST::Server.prune_count(@bot.token, @id, days) response['pruned'] end |
#public_updates_channel ⇒ Channel?
Get the public updates channel of the server.
1254 1255 1256 |
# File 'lib/onyxcord/models/server.rb', line 1254 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.
1113 1114 1115 |
# File 'lib/onyxcord/models/server.rb', line 1113 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.
976 977 978 |
# File 'lib/onyxcord/models/server.rb', line 976 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.
982 983 984 |
# File 'lib/onyxcord/models/server.rb', line 982 def region=(region) update_data(OnyxCord::Internal::JSON.parse(REST::Server.update!(@bot.token, @id, region: region.to_s))) end |
#role(id) ⇒ Role?
Gets a role on this server based on its ID.
164 165 166 |
# File 'lib/onyxcord/models/server.rb', line 164 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.
176 177 178 179 180 |
# File 'lib/onyxcord/models/server.rb', line 176 def role_member_counts response = OnyxCord::Internal::JSON.parse(REST::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.
157 158 159 |
# File 'lib/onyxcord/models/server.rb', line 157 def roles @roles.values end |
#rules_channel ⇒ Channel?
Get the rules channel of the server.
1236 1237 1238 |
# File 'lib/onyxcord/models/server.rb', line 1236 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.
1248 1249 1250 |
# File 'lib/onyxcord/models/server.rb', line 1248 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.
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/onyxcord/models/server.rb', line 1164 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 = OnyxCord::Internal::JSON.parse(REST::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.
1154 1155 1156 1157 1158 |
# File 'lib/onyxcord/models/server.rb', line 1154 def scheduled_events(bypass_cache: false) process_scheduled_events(OnyxCord::Internal::JSON.parse(REST::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.
853 854 855 856 857 858 |
# File 'lib/onyxcord/models/server.rb', line 853 def search_members(name:, limit: nil) response = OnyxCord::Internal::JSON.parse(REST::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.
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 612 613 614 615 616 617 618 619 |
# File 'lib/onyxcord/models/server.rb', line 535 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 = OnyxCord::Internal::JSON.parse(REST::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
313 314 315 |
# File 'lib/onyxcord/models/server.rb', line 313 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
296 297 298 |
# File 'lib/onyxcord/models/server.rb', line 296 def (value, reason = nil) (value, , reason) end |
#splash_url(format: 'webp') ⇒ String?
Utility method to get a server's splash URL.
437 438 439 |
# File 'lib/onyxcord/models/server.rb', line 437 def splash_url(format: 'webp') REST.splash_url(@id, @splash_id, format) if @splash_id end |
#system_channel ⇒ Channel?
Get the system channel of the server.
1242 1243 1244 |
# File 'lib/onyxcord/models/server.rb', line 1242 def system_channel @bot.channel(@system_channel_id) if @system_channel_id end |
#system_channel=(system_channel) ⇒ Object
Sets the server's system channel.
1000 1001 1002 |
# File 'lib/onyxcord/models/server.rb', line 1000 def system_channel=(system_channel) modify(system_channel: system_channel) end |
#text_channels ⇒ Array<Channel>
Returns an array of text channels on this server.
387 388 389 |
# File 'lib/onyxcord/models/server.rb', line 387 def text_channels @channels.select(&:text?) end |
#unban(user, reason = nil) ⇒ Object
Unbans a previously banned user from this server.
920 921 922 |
# File 'lib/onyxcord/models/server.rb', line 920 def unban(user, reason = nil) REST::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.
1103 1104 1105 1106 1107 |
# File 'lib/onyxcord/models/server.rb', line 1103 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').
1020 1021 1022 |
# File 'lib/onyxcord/models/server.rb', line 1020 def verification_level VERIFICATION_LEVELS.key(@verification_level) end |
#verification_level=(level) ⇒ Object
Sets the verification level of the server
1026 1027 1028 |
# File 'lib/onyxcord/models/server.rb', line 1026 def verification_level=(level) modify(verification_level: level) end |
#voice_channels ⇒ Array<Channel>
Returns an array of voice channels on this server.
392 393 394 |
# File 'lib/onyxcord/models/server.rb', line 392 def voice_channels @channels.select(&:voice?) end |
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the server.
1138 1139 1140 1141 |
# File 'lib/onyxcord/models/server.rb', line 1138 def webhooks webhooks = OnyxCord::Internal::JSON.parse(REST::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.
427 428 429 430 431 |
# File 'lib/onyxcord/models/server.rb', line 427 def (style) update_data if @widget_enabled.nil? REST.(@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.
278 279 280 281 |
# File 'lib/onyxcord/models/server.rb', line 278 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
304 305 306 |
# File 'lib/onyxcord/models/server.rb', line 304 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
287 288 289 |
# File 'lib/onyxcord/models/server.rb', line 287 def (value) (value, ) end |
#widget_enabled? ⇒ true, false Also known as: widget?, embed_enabled, embed?
Returns whether or not the server has widget enabled.
269 270 271 272 |
# File 'lib/onyxcord/models/server.rb', line 269 def if @widget_enabled.nil? @widget_enabled end |