Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Includes:
- IDObject, ServerAttributes
- Defined in:
- lib/discordrb/data.rb
Overview
A server on Discord
Instance Attribute Summary collapse
-
#afk_channel ⇒ Channel?
The AFK voice channel of this server, or nil if none is set.
-
#afk_timeout ⇒ Integer
The amount of time after which a voice user gets moved into the AFK channel, in seconds.
-
#channels ⇒ Array<Channel>
readonly
An array of all the channels (text and voice) on this server.
-
#emoji ⇒ Array<Emoji>
(also: #emojis)
readonly
An array of all the emoji available on this server.
-
#features ⇒ Array<Symbol>
readonly
The features of the server (eg. "INVITE_SPLASH").
-
#large ⇒ true, false
(also: #large?)
readonly
it means the members list may be inaccurate for a couple seconds after starting up the bot.
-
#member_count ⇒ Integer
readonly
The absolute number of members on this server, offline or not.
-
#owner ⇒ Member
The server owner.
-
#region ⇒ String
The region the server is on (e. g.
amsterdam
). -
#roles ⇒ Array<Role>
readonly
An array of all the roles created on this server.
-
#verification_level ⇒ Symbol
readonly
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').
-
#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
-
#any_emoji? ⇒ true, false
(also: #has_emoji?, #emoji?)
Whether this server has any emoji or not.
-
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
-
#bans ⇒ Array<User>
A list of banned users on this server.
-
#create_channel(name, type = 0) ⇒ Channel
Creates a channel on this server with the given name.
-
#create_role ⇒ Role
Creates a role on this server which can then be modified.
-
#default_channel ⇒ Channel
(also: #general_channel)
The default channel on this server (usually called #general).
-
#delete ⇒ Object
Deletes this server.
-
#embed? ⇒ true, false
Whether or not the server has widget enabled.
-
#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 all the integrations connected to this server.
-
#kick(user) ⇒ Object
Kicks a user from this server.
-
#leave ⇒ Object
Leave the server.
-
#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.
-
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel.
-
#name=(name) ⇒ Object
Sets the server's name.
-
#online_members(include_idle: false, include_bots: true) ⇒ Array<Member>
(also: #online_users)
An array of online members on this server.
-
#role(id) ⇒ Object
Gets a role on this server based on its ID.
-
#splash_id ⇒ String
The hexadecimal ID used to identify this server's splash image for their VIP invite page.
-
#splash_url ⇒ String?
The splash image URL for the server's VIP invite page.
-
#text_channels ⇒ Array<Channel>
An array of text channels on this server.
-
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
-
#voice_channels ⇒ Array<Channel>
An array of voice channels on this 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_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
Instance Attribute Details
#afk_channel ⇒ Channel?
Returns the AFK voice channel of this server, or nil if none is set.
2032 2033 2034 |
# File 'lib/discordrb/data.rb', line 2032 def afk_channel @afk_channel end |
#afk_timeout ⇒ Integer
Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.
2029 2030 2031 |
# File 'lib/discordrb/data.rb', line 2029 def afk_timeout @afk_timeout end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
2005 2006 2007 |
# File 'lib/discordrb/data.rb', line 2005 def channels @channels end |
#emoji ⇒ Array<Emoji> (readonly) Also known as: emojis
Returns an array of all the emoji available on this server.
2011 2012 2013 |
# File 'lib/discordrb/data.rb', line 2011 def emoji @emoji end |
#features ⇒ Array<Symbol> (readonly)
Returns the features of the server (eg. "INVITE_SPLASH").
2020 2021 2022 |
# File 'lib/discordrb/data.rb', line 2020 def features @features end |
#large ⇒ true, false (readonly) Also known as: large?
it means the members list may be inaccurate for a couple seconds after starting up the bot.
2016 2017 2018 |
# File 'lib/discordrb/data.rb', line 2016 def large @large end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
2023 2024 2025 |
# File 'lib/discordrb/data.rb', line 2023 def member_count @member_count end |
#owner ⇒ Member
Returns The server owner.
2002 2003 2004 |
# File 'lib/discordrb/data.rb', line 2002 def owner @owner end |
#region ⇒ String
Returns the region the server is on (e. g. amsterdam
).
1999 2000 2001 |
# File 'lib/discordrb/data.rb', line 1999 def region @region end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
2008 2009 2010 |
# File 'lib/discordrb/data.rb', line 2008 def roles @roles end |
#verification_level ⇒ Symbol (readonly)
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').
2026 2027 2028 |
# File 'lib/discordrb/data.rb', line 2026 def verification_level @verification_level end |
#voice_states ⇒ Hash<Integer => VoiceState> (readonly)
Returns the hash (user ID => voice state) of voice states of members on this server.
2035 2036 2037 |
# File 'lib/discordrb/data.rb', line 2035 def voice_states @voice_states end |
Instance Method Details
#any_emoji? ⇒ true, false Also known as: has_emoji?, emoji?
Returns whether this server has any emoji or not.
2370 2371 2372 |
# File 'lib/discordrb/data.rb', line 2370 def any_emoji? @emoji.any? end |
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
2294 2295 2296 |
# File 'lib/discordrb/data.rb', line 2294 def ban(user, = 0) API::Server.ban_user(@bot.token, @id, user.resolve_id, ) end |
#bans ⇒ Array<User>
Returns a list of banned users on this server.
2286 2287 2288 2289 |
# File 'lib/discordrb/data.rb', line 2286 def bans users = JSON.parse(API::Server.bans(@bot.token, @id)) users.map { |e| User.new(e['user'], @bot) } end |
#create_channel(name, type = 0) ⇒ Channel
Creates a channel on this server with the given name.
2268 2269 2270 2271 2272 |
# File 'lib/discordrb/data.rb', line 2268 def create_channel(name, type = 0) raise ArgumentError, 'Channel type must be either 0 (text) or 2 (voice)!' unless [0, 2].include?(type) response = API::Server.create_channel(@bot.token, @id, name, type) Channel.new(JSON.parse(response), @bot) end |
#create_role ⇒ Role
Creates a role on this server which can then be modified. It will be initialized (on Discord's side) with the regular role defaults the client uses, i. e. name is "new role", permissions are the default, colour is the default etc.
2278 2279 2280 2281 2282 2283 |
# File 'lib/discordrb/data.rb', line 2278 def create_role response = API::Server.create_role(@bot.token, @id) role = Role.new(JSON.parse(response), @bot, self) @roles << role role end |
#default_channel ⇒ Channel Also known as: general_channel
Returns The default channel on this server (usually called #general).
2070 2071 2072 |
# File 'lib/discordrb/data.rb', line 2070 def default_channel @bot.channel(@id) end |
#delete ⇒ Object
Deletes this server. Be aware that this is permanent and impossible to undo, so be careful!
2318 2319 2320 |
# File 'lib/discordrb/data.rb', line 2318 def delete API::Server.delete(@bot.token, @id) end |
#embed? ⇒ true, false
Returns whether or not the server has widget enabled.
2122 2123 2124 2125 |
# File 'lib/discordrb/data.rb', line 2122 def if @embed.nil? @embed end |
#icon=(icon) ⇒ Object
Sets the server's icon.
2347 2348 2349 2350 2351 2352 2353 2354 2355 |
# File 'lib/discordrb/data.rb', line 2347 def icon=(icon) if icon.respond_to? :read icon_string = 'data:image/jpg;base64,' icon_string += Base64.strict_encode64(icon.read) update_server_data(icon: icon_string) else update_server_data(icon: icon) end end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
2415 2416 2417 |
# File 'lib/discordrb/data.rb', line 2415 def inspect "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} afk_timeout=#{@afk_timeout}>" end |
#integrations ⇒ Array<Integration>
Returns an array of all the integrations connected to this server.
2109 2110 2111 2112 |
# File 'lib/discordrb/data.rb', line 2109 def integrations integration = JSON.parse(API.server_integrations(@bot.token, @id)) integration.map { |element| Integration.new(element, @bot, self) } end |
#kick(user) ⇒ Object
Kicks a user from this server.
2306 2307 2308 |
# File 'lib/discordrb/data.rb', line 2306 def kick(user) API::Server.remove_member(@bot.token, @id, user.resolve_id) end |
#leave ⇒ Object
Leave the server
2323 2324 2325 |
# File 'lib/discordrb/data.rb', line 2323 def leave API::User.leave_server(@bot.token, @id) end |
#member(id, request = true) ⇒ Object
Gets a member on this server based on user ID
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 |
# File 'lib/discordrb/data.rb', line 2085 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 rescue nil end |
#members ⇒ Array<Member> Also known as: users
Returns an array of all the members on this server.
2097 2098 2099 2100 2101 2102 2103 2104 |
# File 'lib/discordrb/data.rb', line 2097 def members return @members.values if @chunked @bot.debug("Members for server #{@id} not chunked yet - initiating") @bot.request_chunks(@id) sleep 0.05 until @chunked @members.values end |
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed.
2313 2314 2315 |
# File 'lib/discordrb/data.rb', line 2313 def move(user, channel) API::Server.update_member(@bot.token, @id, user.id, channel_id: channel.id) end |
#name=(name) ⇒ Object
Sets the server's name.
2335 2336 2337 |
# File 'lib/discordrb/data.rb', line 2335 def name=(name) update_server_data(name: name) 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.
2130 2131 2132 2133 2134 |
# File 'lib/discordrb/data.rb', line 2130 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 |
#role(id) ⇒ Object
Gets a role on this server based on its ID.
2078 2079 2080 |
# File 'lib/discordrb/data.rb', line 2078 def role(id) @roles.find { |e| e.id == id } end |
#splash_id ⇒ String
Returns the hexadecimal ID used to identify this server's splash image for their VIP invite page.
2171 2172 2173 2174 |
# File 'lib/discordrb/data.rb', line 2171 def splash_id @splash_id = JSON.parse(API.server(@bot.token, @id))['splash'] if @splash_id.nil? @splash_id end |
#splash_url ⇒ String?
Returns the splash image URL for the server's VIP invite page.
nil
if there is no splash image.
2178 2179 2180 2181 2182 |
# File 'lib/discordrb/data.rb', line 2178 def splash_url splash_id if @splash_id.nil? return nil unless @splash_id API.splash_url(@id, @splash_id) end |
#text_channels ⇒ Array<Channel>
Returns an array of text channels on this server.
2139 2140 2141 |
# File 'lib/discordrb/data.rb', line 2139 def text_channels @channels.select(&:text?) end |
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
2300 2301 2302 |
# File 'lib/discordrb/data.rb', line 2300 def unban(user) API::Server.unban_user(@bot.token, @id, user.resolve_id) end |
#voice_channels ⇒ Array<Channel>
Returns an array of voice channels on this server.
2144 2145 2146 |
# File 'lib/discordrb/data.rb', line 2144 def voice_channels @channels.select(&:voice?) 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.
2164 2165 2166 2167 2168 |
# File 'lib/discordrb/data.rb', line 2164 def (style) return nil unless @embed if @embed.nil? API.(@id, style) end |