Async::DiscordSourceAsyncDiscordClient

class Client

A client for interacting with Discord.

Definitions

ENDPOINT = Async::HTTP::Endpoint.parse("https://discord.com/api/v10/")

The default endpoint for Discord.

USER_AGENT = "#{self.name} (https://github.com/socketry/async-discord, v#{Async::Discord::VERSION})"

The default user agent for this client.

def authenticated(bot: nil, bearer: nil)

Authenticate the client, either with a bot or bearer token.

Signature

parameter bot String

The bot token.

parameter bearer String

The bearer token.

returns Client

a new client with the given authentication.

Implementation

def authenticated(bot: nil, bearer: nil)
	headers = {}
	
	headers["user-agent"] ||= USER_AGENT
	
	if bot
		headers["authorization"] = "Bot #{bot}"
	elsif bearer
		headers["authorization"] = "Bearer #{bearer}"
	else
		raise ArgumentError, "You must provide either a bot or bearer token!"
	end
	
	return self.with(headers: headers)
end

def guilds

Signature

returns Guilds

a collection of guilds the bot is a member of.

Implementation

def guilds
	Guilds.new(self.with(path: "users/@me/guilds"))
end

def gateway

Signature

returns Gateway

the gateway for the bot.

Implementation

def gateway
	Gateway.new(self.with(path: "gateway/bot"))
end

def channel(id)

Signature

returns Channel

a channel by its unique identifier.

Implementation

def channel(id)
	Channel.new(self.with(path: "channels/#{id}"))
end