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.
1147 1148 1149 |
# File 'lib/discordrb/data.rb', line 1147 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.
1144 1145 1146 |
# File 'lib/discordrb/data.rb', line 1144 def afk_timeout @afk_timeout end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
1130 1131 1132 |
# File 'lib/discordrb/data.rb', line 1130 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.
1137 1138 1139 |
# File 'lib/discordrb/data.rb', line 1137 def large @large end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
1141 1142 1143 |
# File 'lib/discordrb/data.rb', line 1141 def member_count @member_count end |
#owner ⇒ Member
Returns The server owner.
1127 1128 1129 |
# File 'lib/discordrb/data.rb', line 1127 def owner @owner end |
#region ⇒ String
Returns the region the server is on (e. g. amsterdam).
1124 1125 1126 |
# File 'lib/discordrb/data.rb', line 1124 def region @region end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
1133 1134 1135 |
# File 'lib/discordrb/data.rb', line 1133 def roles @roles end |
Instance Method Details
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
1287 1288 1289 |
# File 'lib/discordrb/data.rb', line 1287 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.
1279 1280 1281 1282 |
# File 'lib/discordrb/data.rb', line 1279 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.
1262 1263 1264 1265 |
# File 'lib/discordrb/data.rb', line 1262 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.
1271 1272 1273 1274 1275 1276 |
# File 'lib/discordrb/data.rb', line 1271 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).
1174 1175 1176 |
# File 'lib/discordrb/data.rb', line 1174 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!
1311 1312 1313 |
# File 'lib/discordrb/data.rb', line 1311 def delete API.delete_server(@bot.token, @id) end |
#icon=(icon) ⇒ Object
Sets the server's icon.
1340 1341 1342 1343 1344 1345 1346 1347 1348 |
# File 'lib/discordrb/data.rb', line 1340 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
1394 1395 1396 |
# File 'lib/discordrb/data.rb', line 1394 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.
1299 1300 1301 |
# File 'lib/discordrb/data.rb', line 1299 def kick(user) API.kick_user(@bot.token, @id, user.resolve_id) end |
#leave ⇒ Object
Leave the server
1316 1317 1318 |
# File 'lib/discordrb/data.rb', line 1316 def leave API.leave_server(@bot.token, @id) end |
#member(id) ⇒ Object
Gets a member on this server based on user ID
1188 1189 1190 1191 1192 1193 1194 |
# File 'lib/discordrb/data.rb', line 1188 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.
1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/discordrb/data.rb', line 1197 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.
1306 1307 1308 |
# File 'lib/discordrb/data.rb', line 1306 def move(user, channel) API.move_user(@bot.token, @id, user.id, channel.id) end |
#name=(name) ⇒ Object
Sets the server's name.
1328 1329 1330 |
# File 'lib/discordrb/data.rb', line 1328 def name=(name) update_server_data(name: name) end |
#role(id) ⇒ Object
Gets a role on this server based on its ID.
1182 1183 1184 |
# File 'lib/discordrb/data.rb', line 1182 def role(id) @roles.find { |e| e.id == id } end |
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
1293 1294 1295 |
# File 'lib/discordrb/data.rb', line 1293 def unban(user) API.unban_user(@bot.token, @id, user.resolve_id) end |