class Discordrb::Light::LightBot

A bot that only uses the REST part of the API. Hierarchically unrelated to the regular {Discordrb::Bot}. Useful to make applications integrated to Discord over OAuth, for example.

Public Class Methods

new(token) click to toggle source

Create a new LightBot. This does no networking yet, all networking is done by the methods on this class. @param token [String] The token that should be used to authenticate to Discord. Can be an OAuth token or a regular

user account token.
# File lib/discordrb/light/light_bot.rb, line 18
def initialize(token)
  if token.respond_to? :token
    # Parse AccessTokens from the OAuth2 gem
    token = token.token
  end

  unless token.include? '.'
    # Discord user/bot tokens always contain two dots, so if there's none we can assume it's an OAuth token.
    token = "Bearer #{token}" # OAuth tokens have to be prefixed with 'Bearer' for Discord to be able to use them
  end

  @token = token
end

Public Instance Methods

connections() click to toggle source

Gets the connections associated with this account. @return [Array<Connection>] this account's connections.

# File lib/discordrb/light/light_bot.rb, line 53
def connections
  response = Discordrb::API::User.connections(@token)
  JSON.parse(response).map { |e| Connection.new(e, self) }
end
join(code) click to toggle source

Joins a server using an instant invite. @param code [String] The code part of the invite (for example 0cDvIgU2voWn4BaD if the invite URL is

https://discord.gg/0cDvIgU2voWn4BaD)
# File lib/discordrb/light/light_bot.rb, line 47
def join(code)
  Discordrb::API::Invite.accept(@token, code)
end
profile() click to toggle source

@return [LightProfile] the details of the user this bot is connected to.

# File lib/discordrb/light/light_bot.rb, line 33
def profile
  response = Discordrb::API::User.profile(@token)
  LightProfile.new(JSON.parse(response), self)
end
servers() click to toggle source

@return [Array<LightServer>] the servers this bot is connected to.

# File lib/discordrb/light/light_bot.rb, line 39
def servers
  response = Discordrb::API::User.servers(@token)
  JSON.parse(response).map { |e| LightServer.new(e, self) }
end