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

TODO:

Make this a reader that returns a Channel

Returns the channel ID of the AFK channel, or nil if none is set.

Returns:

  • (Integer)

    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_timeoutInteger

Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.

Returns:

  • (Integer)

    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

#channelsArray<Channel> (readonly)

Returns an array of all the channels (text and voice) on this server.

Returns:

  • (Array<Channel>)

    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

#iconString

TODO:

Make this behave like user.avatar where a URL is available as well.

Returns the hexadecimal ID used to identify this server's icon.

Returns:

  • (String)

    the hexadecimal ID used to identify this server's icon.



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

def icon
  @icon
end

#idInteger (readonly) Also known as: resolve_id

Returns the ID used to uniquely identify this server.

Returns:

  • (Integer)

    the ID used to uniquely identify this server.



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

def id
  @id
end

#membersArray<User> (readonly)

Returns an array of all the users on this server.

Returns:

  • (Array<User>)

    an array of all the users on this server.



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

def members
  @members
end

#nameString

Returns this server's name.

Returns:

  • (String)

    this server's name.



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

def name
  @name
end

#ownerUser

Returns The server owner.

Returns:

  • (User)

    The server owner.



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.

Returns:

  • (Integer)

    the server owner's user ID.



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

def owner_id
  @owner_id
end

#regionString

Returns the region the server is on (e. g. amsterdam).

Returns:

  • (String)

    the region the server is on (e. g. amsterdam).



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

def region
  @region
end

#rolesArray<Role> (readonly)

Returns an array of all the roles created on this server.

Returns:

  • (Array<Role>)

    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.

Parameters:

  • afk_channel (Channel, nil)

    The new AFK channel, or nil if there should be none set.



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.

Parameters:

  • user (User)

    The user to ban.

  • message_days (Integer) (defaults to: 0)

    How many days worth of messages sent by the user should be deleted.



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.

Returns:

  • (Channel)

    the created channel.



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.

Returns:

  • (Role)

    the created role.



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

Returns The default channel on this server (usually called #general).

Returns:

  • (Channel)

    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

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

Parameters:

  • user (User)

    The user to kick.



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.

Parameters:

  • user (User)

    The user to move.

  • channel (Channel)

    The voice channel to move into.



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.

Parameters:

  • id (Integer)

    The role ID to look for.



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.

Parameters:

  • user (User)

    The user to unban.



875
876
877
# File 'lib/discordrb/data.rb', line 875

def unban(user)
  API.unban_user(@bot.token, @id, user.id)
end