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.
-
#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.
Attributes included from ServerAttributes
Attributes included from IDObject
Instance Method Summary collapse
-
#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 = 'text') ⇒ 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.
-
#icon=(icon) ⇒ Object
Sets the server's icon.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#kick(user) ⇒ Object
Kicks a user from this server.
-
#leave ⇒ Object
Leave the server.
-
#member(id) ⇒ 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.
-
#role(id) ⇒ Object
Gets a role on this server based on its ID.
-
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
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.
1116 1117 1118 |
# File 'lib/discordrb/data.rb', line 1116 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.
1113 1114 1115 |
# File 'lib/discordrb/data.rb', line 1113 def afk_timeout @afk_timeout end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
1099 1100 1101 |
# File 'lib/discordrb/data.rb', line 1099 def channels @channels 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.
1106 1107 1108 |
# File 'lib/discordrb/data.rb', line 1106 def large @large end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
1110 1111 1112 |
# File 'lib/discordrb/data.rb', line 1110 def member_count @member_count end |
#owner ⇒ Member
Returns The server owner.
1096 1097 1098 |
# File 'lib/discordrb/data.rb', line 1096 def owner @owner end |
#region ⇒ String
Returns the region the server is on (e. g. amsterdam).
1093 1094 1095 |
# File 'lib/discordrb/data.rb', line 1093 def region @region end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
1102 1103 1104 |
# File 'lib/discordrb/data.rb', line 1102 def roles @roles end |
Instance Method Details
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
1256 1257 1258 |
# File 'lib/discordrb/data.rb', line 1256 def ban(user, = 0) API.ban_user(@bot.token, @id, user.resolve_id, ) end |
#bans ⇒ Array<User>
Returns a list of banned users on this server.
1248 1249 1250 1251 |
# File 'lib/discordrb/data.rb', line 1248 def bans users = JSON.parse(API.bans(@bot.token, @id)) users.map { |e| User.new(e['user'], @bot) } end |
#create_channel(name, type = 'text') ⇒ Channel
Creates a channel on this server with the given name.
1231 1232 1233 1234 |
# File 'lib/discordrb/data.rb', line 1231 def create_channel(name, type = 'text') response = API.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.
1240 1241 1242 1243 1244 1245 |
# File 'lib/discordrb/data.rb', line 1240 def create_role response = API.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).
1143 1144 1145 |
# File 'lib/discordrb/data.rb', line 1143 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!
1280 1281 1282 |
# File 'lib/discordrb/data.rb', line 1280 def delete API.delete_server(@bot.token, @id) end |
#icon=(icon) ⇒ Object
Sets the server's icon.
1309 1310 1311 1312 1313 1314 1315 1316 1317 |
# File 'lib/discordrb/data.rb', line 1309 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
1363 1364 1365 |
# File 'lib/discordrb/data.rb', line 1363 def inspect "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} afk_timeout=#{@afk_timeout}>" end |
#kick(user) ⇒ Object
Kicks a user from this server.
1268 1269 1270 |
# File 'lib/discordrb/data.rb', line 1268 def kick(user) API.kick_user(@bot.token, @id, user.resolve_id) end |
#leave ⇒ Object
Leave the server
1285 1286 1287 |
# File 'lib/discordrb/data.rb', line 1285 def leave API.leave_server(@bot.token, @id) end |
#member(id) ⇒ Object
Gets a member on this server based on user ID
1157 1158 1159 1160 1161 1162 1163 |
# File 'lib/discordrb/data.rb', line 1157 def member(id) id = id.resolve_id return @members[id] if member_cached?(id) member = bot.member(@id, id) @members[id] = member end |
#members ⇒ Array<Member> Also known as: users
Returns an array of all the members on this server.
1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'lib/discordrb/data.rb', line 1166 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.
1275 1276 1277 |
# File 'lib/discordrb/data.rb', line 1275 def move(user, channel) API.move_user(@bot.token, @id, user.id, channel.id) end |
#name=(name) ⇒ Object
Sets the server's name.
1297 1298 1299 |
# File 'lib/discordrb/data.rb', line 1297 def name=(name) update_server_data(name: name) end |
#role(id) ⇒ Object
Gets a role on this server based on its ID.
1151 1152 1153 |
# File 'lib/discordrb/data.rb', line 1151 def role(id) @roles.find { |e| e.id == id } end |
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
1262 1263 1264 |
# File 'lib/discordrb/data.rb', line 1262 def unban(user) API.unban_user(@bot.token, @id, user.resolve_id) end |