Interactions

Interactions

class discord_interactions.flask_ext.Interactions(app: flask.app.Flask, public_key: str, app_id: Optional[int] = None, path: str = '/')
command(command: Optional[Union[discord_interactions.application_command.ApplicationCommand, str, Callable[], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[Union[discord_interactions.interaction.Interaction, discord_interactions.ocm.command.Command, discord_interactions.ocm.command.Option, discord_interactions.flask_ext.context.CommandContext]], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[discord_interactions.flask_ext.context.CommandContext, Any], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Type[discord_interactions.ocm.command.Command]]] = None)Union[Callable[[Union[Callable[], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[Union[discord_interactions.interaction.Interaction, discord_interactions.ocm.command.Command, discord_interactions.ocm.command.Option, discord_interactions.flask_ext.context.CommandContext]], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[discord_interactions.flask_ext.context.CommandContext, Any], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]]]], discord_interactions.flask_ext.interactions.CommandData], discord_interactions.flask_ext.interactions.CommandData]

A decorator to register a slash command. Calls register_command() internally.

Parameters

command – The command that the decorated function is called on

property commands: List[discord_interactions.application_command.ApplicationCommand]

All registered application commands

publish_commands(client: discord_interactions.client.ApplicationClient, guild: Optional[int] = None)

Create all registered commands as application commands at Discord.

Note

This performs a bulk overwrite, which means that currently registered commands that are not registered to the Interactions object will be deleted. If you only want to create specific commands, use ApplicationClient.create_command().

Parameters
  • client (ApplicationClient) – The application client to use for registering the commands at Discord.

  • guild (int) – ID of the optional guild to register the commands at. Commands will be registered globally if left None.

register_command(command: Union[discord_interactions.application_command.ApplicationCommand, Type[discord_interactions.ocm.command.Command], str], callback: Union[Callable[], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[Union[discord_interactions.interaction.Interaction, discord_interactions.ocm.command.Command, discord_interactions.ocm.command.Option, discord_interactions.flask_ext.context.CommandContext]], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[discord_interactions.flask_ext.context.CommandContext, Any], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]]])discord_interactions.flask_ext.interactions.CommandData

Register a callback function for a Discord Slash Command.

Parameters
  • command – The command that the callback is registered for

  • callback – The function that is called when the command is triggered

Returns

An object containing all the command data (e.g. structure, callbacks)

CommandData

class discord_interactions.flask_ext.CommandData(name: str, cb: Union[Callable[], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[Union[discord_interactions.interaction.Interaction, discord_interactions.ocm.command.Command, discord_interactions.ocm.command.Option, discord_interactions.flask_ext.context.CommandContext]], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]], Callable[[discord_interactions.flask_ext.context.CommandContext, Any], Union[discord_interactions.interaction_response.InteractionResponse, str, None, Tuple[Optional[str], bool]]]], cmd: Optional[discord_interactions.application_command.ApplicationCommand] = None)

Stores and handles registering callbacks for a registered command.

Parameters
  • name (str) – Name of the command.

  • cb – The function to be called when the command is invoked.

  • cmd (Optional[ApplicationCommand]) – The object storing structural information for the command.