Events

The library provides you with some new events related to interactions.
Let’s assume that you have this in your code:
from discord.ext import commands
from dislash import *

bot = commands.Bot(command_prefix="!")
slash = SlashClient(bot)

Here’re 3 different ways of working with dislash events:

@slash.event
async def on_event():
    # ...
@bot.listen()
async def on_event():
    # ...
# For cogs
@commands.Cog.listener()
async def on_event(self):
    # ...

on_ready

async events.on_ready()

An event which is activated when the dislash extension is ready and all slash commands are synced (if there’re any)

on_auto_register

async events.on_auto_register(global_commands_patched, patched_guilds)

An event which is called after auto synchronisation of commands.

Parameters
  • global_commands_patched (bool) – whether the global application commands were updated

  • patched_guilds (List[int]) – the list of IDs of guilds where the commands were updated

on_button_click

async events.on_button_click(interaction)

An event which is called on any button click of your application.

Parameters

interaction (MessageInteraction) – the interaction with the button

on_dropdown

async events.on_dropdown(interaction)

An event which is called on any menu click of your application.

Parameters

interaction (MessageInteraction) – the interaction with the select menu

on_slash_command

async events.on_slash_command(interaction)

An event which is called every time a slash command of your application is invoked.

Parameters

interaction (SlashInteraction) – the interaction with a slash command

on_user_command

async events.on_user_command(interaction)

An event which is called every time a user command of your application is invoked.

Parameters

interaction (ContextMenuInteraction) – the interaction with a user command

on_message_command

async events.on_message_command(interaction)

An event which is called every time a message command of your application is invoked.

Parameters

interaction (ContextMenuInteraction) – the interaction with a message command

on_slash_command_error

async events.on_slash_command_error(interaction, error)

An event which is called every time a slash command fails due to some error. This also includes InteractionCheckFailure

Parameters
  • interaction (SlashInteraction) – the interaction with a slash command

  • error (ApplicationCommandError) – the error that was raised

on_user_command_error

async events.on_user_command_error(interaction, error)

An event which is called every time a user command fails due to some error. This also includes InteractionCheckFailure

Parameters
  • interaction (ContextMenuInteraction) – the interaction with a user command

  • error (ApplicationCommandError) – the error that was raised

on_message_command_error

async events.on_message_command_error(interaction, error)

An event which is called every time a message command fails due to some error. This also includes InteractionCheckFailure

Parameters
  • interaction (ContextMenuInteraction) – the interaction with a message command

  • error (ApplicationCommandError) – the error that was raised