Skip to content

Client API

Note

The following classes come from the discord.client module.


Client

Bases: ClientLike

Main entry point for Discord bots. Ties together the moving parts: gateway, HTTP, event dispatching, command handling, and resource managers.

Parameters:

  • token (str) –

    the bot's token

  • application_id (int) –

    the bot's user ID

  • intents (int, default: DEFAULT ) –

    gateway intents. Defaults to Intents.DEFAULT.

  • config (BaseConfig, default: None ) –

    user-defined config data

  • debug_mode (bool, default: False ) –

    toggle debug messages. Defaults to False.

  • prefix (str, default: None ) –

    set message prefix if using command prefixes

  • quiet (bool, default: False ) –

    if INFO, DEBUG, and WARN should be logged

token = token instance-attribute

application_id = application_id instance-attribute

config = config instance-attribute

emojis = BotEmojis(self._http, self.application_id) instance-attribute

prefix_command

Decorator registers prefix commands by the name of the function.

Parameters:

  • func (callable) –

    callback handle for command response

component

Decorator registers a function for a component handler.

Parameters:

  • custom_id (str) –

    Identifier of the component

    Important

    Must match the custom_id set where the component was created.

command

Decorator registers a function for a command handler.

Parameters:

event

Decorator registers a function for an event handler.

Parameters:

  • event_name (str) –

    event name (must be a valid event)

setup_hook

Decorator registers a setup hook. (Runs once before the bot starts listening)

Parameters:

  • func (callable) –

    callback to the setup function

shutdown_hook

Decorator registers a shutdown hook. (Runs once before the bot exits the loop)

Parameters:

  • func (callable) –

    callback to the shutdown function

application_from_id

Creates an interactable application resource.

Parameters:

  • application_id (int) –

    id of target application

Returns:

guild_from_id

Creates an interactable guild resource.

Parameters:

  • guild_id (int) –

    id of target guild

Returns:

  • Guild

    the Guild resource

channel_from_id

Creates an interactable channel resource.

Parameters:

  • channel_id (int) –

    id of target channel

Returns:

message_from_id

Creates an interactable message resource.

Parameters:

  • message_id (int) –

    id of target message

  • channel_id (int) –

    channel id of target message

Returns:

user_from_id

Creates an interactable user resource.

Parameters:

  • user_id (int) –

    id of target user

Returns:

  • User

    the User resource

clear_guild_commands async

Clear a guild's slash commands.

Parameters:

  • guild_id (int) –

    id of the target guild

run

Starts the bot. Handles starting the session, WS, and heartbeat, reconnection logic, setting up emojis and hooks, and then listens for gateway events.