Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Defined in:
- lib/discordrb/data.rb
Overview
A server on Discord
Instance Attribute Summary collapse
-
#afk_channel_id ⇒ Integer
The channel ID of the AFK channel, 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.
-
#icon ⇒ String
The hexadecimal ID used to identify this server's icon.
-
#id ⇒ Integer
(also: #resolve_id)
readonly
The ID used to uniquely identify this server.
-
#members ⇒ Array<User>
readonly
An array of all the users on this server.
-
#name ⇒ String
This server's name.
-
#owner ⇒ User
The server owner.
- #owner_id ⇒ Integer readonly deprecated Deprecated.
-
#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.
Instance Method Summary collapse
-
#==(other) ⇒ Object
ID based comparison.
-
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
-
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
-
#create_channel(name) ⇒ 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
(also: #leave)
Deletes this server.
-
#kick(user) ⇒ Object
Kicks a user from this server.
-
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel.
-
#role(id) ⇒ Object
Gets a role on this server based on its ID.
-
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
Instance Attribute Details
#afk_channel_id ⇒ Integer
Make this a reader that returns a Channel
Returns the channel ID of the AFK channel, or nil
if none is set.
775 776 777 |
# File 'lib/discordrb/data.rb', line 775 def afk_channel_id @afk_channel_id end |
#afk_timeout ⇒ Integer
Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.
771 772 773 |
# File 'lib/discordrb/data.rb', line 771 def afk_timeout @afk_timeout end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
761 762 763 |
# File 'lib/discordrb/data.rb', line 761 def channels @channels end |
#icon ⇒ String
Make this behave like user.avatar where a URL is available as well.
Returns the hexadecimal ID used to identify this server's icon.
768 769 770 |
# File 'lib/discordrb/data.rb', line 768 def icon @icon end |
#id ⇒ Integer (readonly) Also known as: resolve_id
Returns the ID used to uniquely identify this server.
755 756 757 |
# File 'lib/discordrb/data.rb', line 755 def id @id end |
#members ⇒ Array<User> (readonly)
Returns an array of all the users on this server.
758 759 760 |
# File 'lib/discordrb/data.rb', line 758 def members @members end |
#name ⇒ String
Returns this server's name.
745 746 747 |
# File 'lib/discordrb/data.rb', line 745 def name @name end |
#owner ⇒ User
Returns The server owner.
752 753 754 |
# File 'lib/discordrb/data.rb', line 752 def owner @owner end |
#owner_id ⇒ Integer (readonly)
749 750 751 |
# File 'lib/discordrb/data.rb', line 749 def owner_id @owner_id end |
#region ⇒ String
Returns the region the server is on (e. g. amsterdam
).
742 743 744 |
# File 'lib/discordrb/data.rb', line 742 def region @region end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
764 765 766 |
# File 'lib/discordrb/data.rb', line 764 def roles @roles end |
Instance Method Details
#==(other) ⇒ Object
ID based comparison
795 796 797 |
# File 'lib/discordrb/data.rb', line 795 def ==(other) Discordrb.id_compare(@id, other) end |
#afk_channel=(afk_channel) ⇒ Object
Sets the server's AFK channel.
928 929 930 |
# File 'lib/discordrb/data.rb', line 928 def afk_channel=(afk_channel) update_server_data(afk_channel_id: afk_channel.resolve_id) end |
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
869 870 871 |
# File 'lib/discordrb/data.rb', line 869 def ban(user, = 0) API.ban_user(@bot.token, @id, user.id, ) end |
#create_channel(name) ⇒ Channel
Creates a channel on this server with the given name.
850 851 852 853 |
# File 'lib/discordrb/data.rb', line 850 def create_channel(name) response = API.create_channel(@bot.token, @id, name, 'text') 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.
859 860 861 862 863 864 |
# File 'lib/discordrb/data.rb', line 859 def create_role response = API.create_role(@bot.token, @id) role = Role.new(JSON.parse(response), @bot) @roles << role role end |
#default_channel ⇒ Channel Also known as: general_channel
Returns The default channel on this server (usually called #general).
800 801 802 |
# File 'lib/discordrb/data.rb', line 800 def default_channel @bot.channel(@id) end |
#delete ⇒ Object Also known as: leave
Deletes this server. Be aware that this is permanent and impossible to undo, so be careful!
893 894 895 |
# File 'lib/discordrb/data.rb', line 893 def delete API.delete_server(@bot.token, @id) end |
#kick(user) ⇒ Object
Kicks a user from this server.
881 882 883 |
# File 'lib/discordrb/data.rb', line 881 def kick(user) API.kick_user(@bot.token, @id, user.id) end |
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed.
888 889 890 |
# File 'lib/discordrb/data.rb', line 888 def move(user, channel) API.move_user(@bot.token, @id, user.id, channel.id) end |
#role(id) ⇒ Object
Gets a role on this server based on its ID.
808 809 810 |
# File 'lib/discordrb/data.rb', line 808 def role(id) @roles.find { |e| e.id == id } end |
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
875 876 877 |
# File 'lib/discordrb/data.rb', line 875 def unban(user) API.unban_user(@bot.token, @id, user.id) end |