Skip to content

DiscordClient

For specific event handlers, see Client Event Handlers.

DiscordClient

Client for interaction with Discord.

__init__(self, token, application_id=None) special

Instantiate a DiscordClient.

Parameters:

Name Type Description Default
token str

Valid token to access discord. Only Bot token's currently supported.

required
application_id str

The application id. Can be left to None if client will not use Interactions.

None

configure_intents(self, guilds=False, guild_members=False, guild_bans=False, guild_emoji_and_stickers=False, guild_integrations=False, guild_webhooks=False, guild_invites=False, guild_voice_states=False, guild_presences=False, guild_messages=False, guild_message_reactions=False, guild_message_typeing=False, direct_messages=False, direct_message_reactions=False, direct_messages_typeing=False)

Configure intents before connecting.

For more details, read the official docs.

Parameters:

Name Type Description Default
guilds bool

Receive events related to guilds the client is a part of.

False
guild_members bool

Receive events related to guild members.

False
guild_bans bool

Receive events related to guild bans.

False
guild_emoji_and_stickers bool

Receive events related to guild emoji and stickers.

False
guild_integrations bool

Receive events related to guild Interactions.

False
guild_webhooks bool

Receive events related to guild Webhooks.

False
guild_invites bool

Receive events related to guild invites

False
guild_voice_states bool

Receive events related to guild voice states.

False
guild_presences bool

Receive events related to guild presences.

False
guild_messages bool

Receive events related to guild messages.

False
guild_message_reactions bool

Receive events related to guild reactions.

False
guild_message_typeing bool

Receive events related to guild members starting to type.

False
direct_messages bool

Receive events related to direct messages.

False
direct_message_reactions bool

Receive events related to direct message reactions.

False
direct_messages_typeing bool

Receive events related to users typing in direct messages.

False

set_all_intents(self)

Set all intents to True. For more information see the configure_intents() function.

run(self, loop=None)

Start the async loop and run forever.

Parameters:

Name Type Description Default
loop asyncio.AbstractEventLoop

If desired, use a given asyncio compatible loop. One will be created if not given.

None

decorate_handler(event) classmethod

Register a given function to a given event string.

This function should be used as a decorator around a function to map that function to a given event. The decorator takes one argument, a string which maps to the type of event we should map to. See the definition of DISCORD_EVENTS for names to map against.

The decorated mapped should by an async function, although synchronous functions are allowed (and highly discouraged).

The arguments of the decorated decide which python objects are given to the function when the given event is called. The mapping is as follows:

  • 1 Argument -> (discord_object)
  • 2 Argument -> (discord_object, raw_dict)
  • 3 Argument -> (discord_object, raw_dict, client)

The discord_object will be a python representation of the event object.

The raw_dict is a raw dictionary the API emitted.

The client is the DiscordClient instance.

decorate_class(target_class) classmethod

Register a given class and attempt to call any valid on_ functions.

By convention functions of the class should be async.