Class: Discordrb::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data.rb

Overview

A server on Discord

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#afk_channel_idInteger



775
776
777
# File 'lib/discordrb/data.rb', line 775

def afk_channel_id
  @afk_channel_id
end

#afk_timeoutInteger



771
772
773
# File 'lib/discordrb/data.rb', line 771

def afk_timeout
  @afk_timeout
end

#channelsArray<Channel> (readonly)



761
762
763
# File 'lib/discordrb/data.rb', line 761

def channels
  @channels
end

#iconString



768
769
770
# File 'lib/discordrb/data.rb', line 768

def icon
  @icon
end

#idInteger (readonly) Also known as: resolve_id



755
756
757
# File 'lib/discordrb/data.rb', line 755

def id
  @id
end

#membersArray<User> (readonly)



758
759
760
# File 'lib/discordrb/data.rb', line 758

def members
  @members
end

#nameString



745
746
747
# File 'lib/discordrb/data.rb', line 745

def name
  @name
end

#ownerUser



752
753
754
# File 'lib/discordrb/data.rb', line 752

def owner
  @owner
end

#owner_idInteger (readonly)

Deprecated.

Use #owner instead, then get the resulting User's User#id.

Returns the server owner's user ID.



749
750
751
# File 'lib/discordrb/data.rb', line 749

def owner_id
  @owner_id
end

#regionString



742
743
744
# File 'lib/discordrb/data.rb', line 742

def region
  @region
end

#rolesArray<Role> (readonly)



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, message_days = 0)
  API.ban_user(@bot.token, @id, user.id, message_days)
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_roleRole

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_channelChannel Also known as: general_channel



800
801
802
# File 'lib/discordrb/data.rb', line 800

def default_channel
  @bot.channel(@id)
end

#deleteObject 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