DiscordClient

Inherits: Node < Object

Description

The facade of the Discord API, used to login to bot accounts.

Properties

type name
BaseDiscordEntityManager entity_manager
DiscordRESTAdapter rest
DiscordWebSocketAdapter gateway_websocket
VoiceWebSocketAdapter voice_websocket
Dictionary commands_map
bool use_http_pool

Methods

return type signature
void login ( )
void logout ( )
void update_presence ( PresenceUpdate presence )
bool is_client_connected ( )
String get_token ( )
int get_intents ( )
int get_ping ( )
int get_uptime_ms ( )
User get_self ( )
User get_user ( int id )
Presence get_presence ( int id )
Guild get_guild ( int id )
Channel get_channel ( int id )
DiscordApplication get_application ( int id )
DiscordApplication get_client_application ( )
DiscordTeam get_team ( int id )
void register_application_command_executor ( String command, ApplicationCommandExecutor executor )
DiscordApplicationCommand register_application_command ( ApplicationCommandBuilder builder, int guild_id=0 ) coroutine

Signals

  • connected ( )

    Emitted when the client connect to Discord's gateway websocket server. To know if the bot is ready refer to client_ready signal


  • reconnected ( )

    Emitted when the client reconnects to Discord's gateway websocket server. The client may attempt to reconnect when it looses connection to the server or when Discord requests a reconnection.


  • resumed ( )

    Emitted when the client resumed the session after reconecting (check reconnected signal).


  • connection_error ( error )

    Emitted when the client fails to connect.

    • int error: Error code.

  • disconnected ( )

    Emitted when the client disconnects from Discord's gateway websocket server.


  • raw_event ( event, payload )

    Emitted when the client receives a Discord event dispatch and before it gets processed internally. https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events

    • String event: Event name.
    • Dictionary payload: Event data.

  • client_ready ( user )

    Emitted when the client is connected and ready to interact with Discord API

    • User user: The connected bot's User object.

  • channel_created ( guild, channel )

    Emitted when a guild channel is created.

    • Guild guild: The guild in which the channel was created.
    • Channel channel: The created channel.

  • channel_updated ( guild, old, new )

    Emitted when a guild channel is updated.

    • Guild guild: The guild in which the channel was updated.
    • Channel old: A copy of the channel before the update.
    • Channel new: The updated channel.

  • channel_deleted ( guild, channel )

    Emitted when a guild channel is deleted.

    • Guild guild: The guild in which the channel was deleted.
    • Channel channel: The deleted channel.

  • channel_pins_updated ( channel, last_pin )

    Emitted when a message is pinned or unpinned in a text channel.

    • TextChannel channel: The channel in which the pins were updated.
    • int last_pin: unix time (in seconds) of the last recent pin.

  • thread_created ( guild, thread )

    Emitted when a thread is created.

    • Guild guild: The guild in which the thread was created.
    • Guild.ThreadChannel thread: The created thread.

  • thread_updated ( guild, old, new )

    Emitted when a thread is updated.

    • Guild guild: The guild in which the thread was updated.
    • Guild.ThreadChannel thread: The updated thread.

  • thread_deleted ( guild, thread )

    Emitted when a thread is updated.

    • Guild guild: The guild in which the thread was deleted.
    • Guild.ThreadChannel thread: The deleted thread.

  • thread_list_sync ( )

    Not implemented


  • thread_member_updated ( )

    Not implemented


  • thread_members_updated ( thread )

    Not implemented


  • typing_started ( channel, user, timestamp )

    Emitted when a thread is updated.

    • Guild guild: The guild in which the thread was deleted.
    • Guild.ThreadChannel thread: The deleted thread. Emitted when a user starts typing in a channel

    • TextChannel channel: The channel in which the thread was deleted.

    • User user: The user who started typing.
    • int timestamp: The unix time (in seconds) of when the user started typing.

  • guild_available ( guild )

    Emitted when a guild becomes available again to the client.

    • Guild guild: The guild object.

  • guild_unavailable ( guild )

    Emitted when a guild becomes unavailable due to an outage.

    • Guild guild: The guild object.

  • guild_created ( guild )

    Emitted when the current user joins a new Guild.

    • Guild guild: The joined guild.

  • guild_updated ( old, new )

    Emitted when a guild is updated.

    • Guild old: A copy of the guild before the update.
    • Guild new: The updated guild.

  • guild_deleted ( guild )

    Emitted when the user leaves or is removed from a guild.

    • Guild guild: The deleted guild.

  • guild_ban_added ( guild, user )

    Emitted when a user is banned from a guild.

    • Guild guild: The guild in which the user was banned.
    • User user: The banned user.

  • guild_ban_removed ( guild, user )

    Emitted when a user is unbanned from a guild.

    • Guild guild: The guild in which the user was unbanned.
    • User user: The unbanned user.

  • guild_emojis_updated ( guild, emojis )

    Emitted when a guild's emojis have been updated.

    • Guild guild: The guild in which the emojis have been updated.
    • Array emojis: List of Emoji objects.

  • guild_role_created ( guild, role )

    Emitted when a guild role is created.

    • Guild guild: The guild in which the role was created.
    • Guild.Role role: The created role.

  • guild_role_updated ( guild, old, new )

    Emitted when a guild role is updated.

    • Guild guild: The guild in which the role was updated.
    • Guild.Role old: A copy of the role before the update.
    • Guild.Role new: The updated role.

  • guild_role_deleted ( guild, role )

    Emitted when a guild role is deleted.

    • Guild guild: The guild in which the role was deleted.
    • Guild.Role role: The deleted role.

  • guild_integrations_updated ( guild, integration )

    Not implemented


  • integration_created ( integration )

    Not implemented


  • integration_updated ( old, new )

    Not implemented


  • integration_deleted ( integration )

    Not implemented


  • interaction_created ( interaction )

    Not implemented


  • invite_created ( invite )

    Not implemented


  • invite_deleted ( invite )

    Not implemented


  • member_joined ( guild, member )

    Emitted when a new user joins a guild.

    • Guild guild: The guild which the user joined.
    • Guild.Member member: The user who joined the guild.

  • member_left ( guild, user )

    Emitted when a user is removed from a guild (leave/kick/ban).

    • Guild guild: The guild in which the user was removed.
    • User user: The the removed user.

  • member_updated ( guild, old, new )

    Emitted when a guild member is updated and the member is found in the internal cache.

    • Guild guild: The guild in which the member was updated.
    • Guild.Member old: A copy of the member before the update.
    • Guild.Member new: The updated member.

  • message_sent ( message )

    Emitted when a message is created.

    • Message message: The created message.

  • message_updated ( old, new )

    Emitted when a message is updated and found in the internal cache

    • Message old: A copy of the message before the update.
    • Message new: The updated message.

  • message_deleted ( message )

    Emitted when a message is updated.

    • Message old: A copy of the message before the update.
    • Message new: The updated message.

  • message_bulk_deleted ( messages, channel )

    Emitted when multiple messages are deleted at once. and at least one of the messages were found in the internal cache

    • Array messages: List of Message objects of the deleted messages.
    • TextChannel channel: The channel in which the messages were deleted.

  • presence_updated ( presence )

    Emitted when a user's presence or info, such as name or avatar, is updated.

    • Presence presence: The presence object.

  • stage_instance_created ( channel, instance )

    Not implemented


  • stage_instance_deleted ( channel, instance )

    Not implemented


  • stage_instance_updated ( channel, old, new )

    Not implemented


  • user_updated ( old, new )

    Not implemented


  • reaction_added ( message, user, reaction )

    Emitted when a user adds a reaction to a message and found in the internal cache.

    • Message message: The message in which the reaction was added.
    • User user: The user who reacted to the message.
    • MessageReaction reaction: The added reaction.

  • reaction_removed ( message, user, reaction )

    Emitted when a user removes a reaction from a message and found in the internal cache.

    • Message message: The message in which the reaction was removed.
    • User user: The user who removed the reaction from the message.
    • MessageReaction reaction: The removed reaction.

  • reactions_cleared ( message, reactions )

    Emitted when a user explicitly removes all reactions from a message.

    • Message message: The message in which the reactions were removed.
    • Array reaction: List of MessageReaction objects of the removed reactions.

  • reactions_cleared_emoji ( message, reaction )

    Emitted when a bot removes all instances of a given emoji from the reactions of a message.

    • Message message: The message in which the reactions were removed.
    • Array reaction: List of MessageReaction objects of the removed reactions.

  • voice_state_updated ( previous, current )

    Emitted when someone joins/leaves/moves voice channels.

    • Guild.VoiceState previous: The previous voice state of the user.
    • Guild.VoiceState current: The current voice state of the user.

  • voice_server_updated ( old, new )

    Not implemented


  • webhooks_updated ( old, new )

    Not implemented

Constants

  • int ERR_WEBSOCKET = 49

    Generic webscoket error.

Property Descriptions

  • BaseDiscordEntityManager entity_manager

    The entity manager instance associated this client.


  • DiscordRESTAdapter rest

    The REST client instance associated this client.


  • DiscordWebSocketAdapter gateway_websocket

    The REST client instance associated this client.


  • VoiceWebSocketAdapter voice_websocket

    Unused, might be removed in the future.


  • Dictionary commands_map

    A dictionary holding registered application/text commands. Should not be modified directly.


  • bool use_http_pool

    If true, the REST client will use an HTTP connection pool to send requests. Must be set before calling login(). This is an unstable experimental feature, it is highly recommended to leave it off, might be removed in the future.

Method Descriptions

  • DiscordClient DiscordClient ( String token, int intents )

    Constructs a new DiscordClient with a bot token. Theintents parameter is used to specify the group of events to be notified about.


  • void login ( )

    Connects to Discord's gateway and identify as a bot account. The node has to be inside a SceneTree or the method will fail.


  • void logout ( )

    Disconnects from Discord's gateway if already connected.


  • void update_presence ( PresenceUpdate presence )

    There is currently no description for this method.


  • bool is_client_connected ( )

    Whether this client instance is in an active connection


  • String get_token ( )

    Gets the associated token.


  • int get_intents ( )

    Gets the associated intents flags.


  • int get_ping ( )

    Gets the gateway server latency in milliseconds.


  • int get_uptime_ms ( )

    Gets the client uptime in milliseconds.


  • User get_self ( )

    Gets the user object of the current connected bot account.


  • User get_user ( int id )

    Gets a user by id.


  • Presence get_presence ( int id )

    Gets a user's presence by id.


  • Guild get_guild ( int id )

    Gets a guild by id.


  • Channel get_channel ( int id )

    Gets a channel by id.


  • DiscordApplication get_application ( int id )

    Gets an application by id.


  • DiscordApplication get_client_application ( )

    Gets a the application object of the current bot account.


  • DiscordTeam get_team ( int id )

    Gets a Discord team object by id.


  • void register_application_command_executor ( String command, ApplicationCommandExecutor executor )

    Registers an applications command executor for command name.


  • DiscordApplicationCommand register_application_command ( ApplicationCommandBuilder builder, int guild_id=0 ) coroutine

    Registers an application command with the help of a command builder object If a guild_id is provided the command will only be registered on that guild, otherwise the command will be registered globally. The method should be called one time only in the whole bot life cycle, calling this with an already registered command will override its configuration.