this is the main class for the discord bot it handles all the incoming messages and events

Methods

Public methods


Method new()

Usage

DiscordrBot$new(token, intent = GUILD_MESSAGES)

Arguments

token

The discord bot token

intent

the intent(s) that the bot should access. Discordr defines constant for the possible intents Closes websocket connection Start the bot


Method finalize()

Usage

DiscordrBot$finalize()


Method start()

starts the bot and enters in an infinite later loop if in a interactive session returns as the later event loop will be run while R is idle

Usage

DiscordrBot$start()


Method register_op_handler()

register op handler

Usage

DiscordrBot$register_op_handler(op, callback)

Arguments

op

one of the opcodes from the discord websocket https://discord.com/developers/docs/topics/opcodes-and-status-codes

callback

a function that would be called with the event data register event handlers


Method register_event_handler()

Usage

DiscordrBot$register_event_handler(event_type, callback)

Arguments

event_type

one of the events from the discord websocket https://discord.com/developers/docs/topics/gateway#commands-and-events

callback

a function that would be called with the event data send payload directly to the websocket


Method send_payload()

Usage

DiscordrBot$send_payload(opcode, data)

Arguments

opcode

websocket OP CODE

data

list that represents data to be sent in payload return the endpoint of Websocket connections general GET request to discord


Method get_ws_endpoint()

Usage

DiscordrBot$get_ws_endpoint()


Method discord_get_api()

Usage

DiscordrBot$discord_get_api(path)

Arguments

path

the path from the discord base api. general POST request to discord


Method discord_post_api()

Usage

DiscordrBot$discord_post_api(path, body)

Arguments

path

the path from the discord base api.

body

a list that will the body of the http request. It will automatically encoded in json create a new websocket and connect to it switcher for op code Switch according to received events hello is the first message sent by discord on the websocket need to setup heartbeat and intent connect to discord sending intents and The session is invalid for discord need to reconnect again resumes previous sessions after they are interrupted reconnect socket if asked by discord save the ready event


Method clone()

The objects of this class are cloneable with this method.

Usage

DiscordrBot$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.