Interaction based Command Handlers

Module which extends Discord.py to allow for custom application commands.

class OverriddenChannel[source]

A modified version of discord.TextChannel which overrides discord.TextChannel.send() to suppress stray deferred ephemeral messages.

Parameters

parent (discord.Interaction) – The original interaction class.

async send()[source]

discord.TextChannel.send() like behavior for OverriddenChannel.

class CustomInteraction[source]

An overrided class of discord.Interaction to provide hybrid behavior between interaction and Message.

Parameters

interaction (discord.Interaction) – The original interaction class.

async reply()[source]

discord.Message.reply() like behavior for Interactions.

async add_reaction()[source]

discord.Message.add_reaction() like behavior for Interactions.

Parameters

reaction (str) – The reaction to add.

class CommandListing[source]

An extending hybrid list to hold instances of AppCommand. Supports accessing a command by name.

Parameters

handler – The command handler object.

property Component: Type[scripts.base.components.AppCommand]

Returns the component class of the handler.

Returns

The component class of the handler.

Return type

Type[AppCommand]

append()[source]

Transform/Ensure that the command is a AppCommand and append it to the list.

Parameters

command (Union[AppCommand, Dict]) – The command to add to the list.

remove()[source]
Remove a command from the list.
Supports lookups by name and ID.
Parameters

command (Union[str, Dict, AppCommand]) – The command to remove from the list.

property names: List[str]
Returns

Stored command names.

Return type

List

async refresh()[source]

Refreshes the command list.

command_to_dict()[source]

Convert a command to a dictionary.

Parameters
  • command (Callable) – Command to convert.

  • local (Optional[bool]) – Whether to use local or official server.

Returns

Dictionary representation of the command.

Return type

Dict[str, Any]

class SlashHandler[source]
Class which handles custom slash commands.
It is an extension of Discord.py’s http module.
async add_slash_commands()[source]

Add all slash commands to the guild/globally.

Parameters

kwargs (Dict) – Keyword arguments to pass to the route.

async delete_command()[source]

Deletes a Slash command to the guild/globally.

Parameters
  • command (Union[SlashCommand, Dict]) – The Command object/dictionary to delete.

  • kwargs (Dict[str, Any]) – Keyword arguments to pass to the route.

async get_command()[source]

Gets the Command Object from its name.

Parameters

command (str) – The command name

Returns

The corresponding Slash Command object.

Return type

SlashCommand

get_route()[source]

Get the route for the query based on the kwargs.

Parameters
  • method (str) – HTTP Method to use.

  • kwargs (Dict[str, Any]) – Keyword arguments to pass to the route.

async parse_response()[source]

Parse the response from the server.

Parameters

interaction (discord.Interaction) – Interaction to parse.

Returns

Parsed command method and additional details.

Return type

Tuple[Callable, Dict[str, Any]]

async register_command()[source]

Register a Slash command to the guild/globally.

Parameters
  • command (str) – Command to register.

  • kwargs (Dict) – Keyword arguments to pass to the route.

class ContextHandler[source]

Class which handles context menus.

Warning

Currently does not support autosync.

Parameters

ctx (bot.PokeGambler) – The pokegambler client.

async delete_command()[source]

Deletes a Context Menu command.

Parameters
  • command (Union[ContextMenu, Dict]) – The Command object/dictionary to delete.

  • kwargs (Dict[str, Any]) – Keyword arguments to pass to the route.

async execute()[source]

Parse the data into components.ContextMenu and executes its callback.

Parameters

interaction (discord.Interaction) – Interaction to parse.

Returns

Parsed command method.

Return type

Callable

get_route()[source]

Get the route for the query.

Parameters

method (str) – HTTP Method to use.

async register_command()[source]

Register a context menu command.

Parameters
  • callback (Callable) – The callback which gets executed upon interaction.

  • type (Optional[int]) – The type of the context menu command.

  • type_ (Optional[int]) –

Returns

The registered context menu command.

Return type

ContextMenu

async register_all()[source]

Registers all the decorated Context Menu commands.

class AutocompleteHandler[source]

Autocomplete handler for commands.

Parameters

ctx (bot.PokeGambler) – The pokegambler client.

register()[source]

Register a command with its choices.

Parameters
  • cmd (Coroutine) – The command to register.

  • callback_dict (Dict[str, Callable[[Interaction], List[Any]]]) – The callback dictionary.

unregister()[source]

Unregister a command.

Parameters

cmd (SlashCommand) – The command to unregister.

async parse()[source]

Get the choices for a command.

Parameters

interaction (discord.Interaction) – The interaction to parse.

Returns

The choices for the command.

Return type

List[discord.app_commands.Choice]

property registered: List[scripts.base.components.SlashCommand]

Get the registered commands.

Returns

The registered commands.

Return type

List[SlashCommand]

class GuildEventHandler[source]

Class which handles guild events.

Parameters

ctx (bot.PokeGambler) – The pokegambler client.

async list_events()[source]

List all the events for a guild.

Parameters

guild_id (Union[int, str]) – The guild id.

Returns

The list of events.

Return type

List[GuildEvent]

async register_event()[source]

Register a guild event.

Parameters
  • guild_id (Union[int, str]) – The guild id.

  • event (GuildEvent) – The event to register.

Returns

The registered event.

Return type

GuildEvent

static dict_to_event()[source]

Convert a dict to a components.GuildEvent

Parameters

event (Dict) – The dict to convert.

Returns

The converted event.

Return type

GuildEvent