Dispatchers¶
Internal API
These classes are for internal use only.
Users should interact with Client and other public API classes instead.
Interaction Dispatcher¶
CommandDispatcher
¶
Central hub for registering and dispatching interaction responses.
RESOURCE_MAP = {InteractionTypes.APPLICATION_COMMAND: ApplicationCommandData, InteractionTypes.MESSAGE_COMPONENT: MessageComponentData, InteractionTypes.MODAL_SUBMIT: ModalData}
class-attribute
instance-attribute
¶
Maps InteractionTypes
to their respective dataclass.
application_id = client.application_id
instance-attribute
¶
Bot's application ID.
bot = client
instance-attribute
¶
Bot session for user access to bot.
_http = client._http
instance-attribute
¶
HTTP session for requests.
_logger = client._logger
instance-attribute
¶
Logger instance to log events.
config = client.config
instance-attribute
¶
_component_handlers = {}
instance-attribute
¶
Mapping of component custom IDs to handler.
_handlers = {}
instance-attribute
¶
Mapping of command names to handler.
_message_handlers = {}
instance-attribute
¶
Mapping of message command names to handler.
_user_handlers = {}
instance-attribute
¶
Mapping of user command names to handler.
_register_guild_commands
async
¶
Registers a command at the guild level.
Parameters:
-
commands
(dict
) –mapping of guild IDs to respective serialized command data
_register_global_commands
async
¶
Registers a command at the global/bot level. (ALL GUILDS)
Parameters:
-
commands
(list
) –list of serialized commands
command
¶
Decorator to register slash commands.
Parameters:
-
name
(str
) –name of the command to register
-
handler
(callable
) –callback handle for command response
user_command
¶
Decorator to register user commands.
Parameters:
-
name
(str
) –name of the command to register
-
handler
(callable
) –callback handle for user command response
message_command
¶
Decorator to register message commands.
Parameters:
-
name
(str
) –name of the command to register
-
handler
(callable
) –callback handle for message command response
component
¶
Decorator to register component interactions.
Parameters:
-
custom_id
(str
) –Identifier of the component
Important
Must match the
custom_id
set where the component was created.
dispatch
async
¶
Dispatch a response to an INTERACTION_CREATE
event
Parameters:
-
data
(dict
) –interaction data
InteractionTypes
¶
Interaction types constants.
Event Dispatcher¶
EventDispatcher
¶
Central hub for handling Discord Gateway events.
RESOURCE_MAP = {'READY': ('discord.events.ready_event', 'ReadyEvent'), 'MESSAGE_CREATE': ('discord.events.message_events', 'MessageCreateEvent')}
class-attribute
instance-attribute
¶
Mapping of event names to respective dataclass.
application_id = client.application_id
instance-attribute
¶
Bot's ID.
bot = client
instance-attribute
¶
Top-level discord client.
_http = client._http
instance-attribute
¶
HTTP session for requests.
_logger = client._logger
instance-attribute
¶
HTTP session for requests
config = client.config
instance-attribute
¶
User-defined bot config for persistent data.
_handlers = {}
instance-attribute
¶
Mapping of event names to handler.
register
¶
Registers the given handler to the given event name. (Event name must be a valid Discord event)
Parameters:
-
event_name
(str
) –name of the event
-
handler
(callable
) –callback to handle event
dispatch
async
¶
Hydrate the corresponding dataclass and call the handler.
Parameters:
-
event_name
(str
) –name of the event
-
data
(dict
) –Discord's raw event payload
Prefix Dispatcher (Legacy)¶
PrefixDispatcher
¶
Handles text-based command messages that start with a specific prefix.
bot = client
instance-attribute
¶
Bot session for user access to bot.
_http = client._http
instance-attribute
¶
HTTP session for requests.
_logger = client._logger
instance-attribute
¶
Logger instance to log events.
prefix = prefix
instance-attribute
¶
User-defined command prefix.
config = client.config
instance-attribute
¶
User-defined bot config for persistent data.
_handlers = {}
instance-attribute
¶
Mapping of command prefix names to handler
register
¶
Registers a handler for a command name (case-insensitive)
Parameters:
-
name
(str
) –name of handler (and command)
-
handler
(callable
) –handler callback
dispatch
async
¶
Hydrate the corresponding dataclass and call the handler.
Parameters:
-
data
(dict
) –Discord's raw event payload