#Slash command timeout

1 messages · Page 1 of 1 (latest)

broken copper
#

Hey, I have a command that takes some time to execute because it needs some processing on the server side. However, if it takes more than 3 seconds to complete, the slash command expires and the await of the commands ouputs a 404 error.

Is there any way to have a longer timeout ?

mossy tulipBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

mossy tulipBOT
#

If your command takes more than 3 seconds to give a response, you might be getting an error back from Discord looking something like this:

This interaction failed. / Unknown interaction.

Discord expects you to respond to an interaction within 3 seconds in some manner. This may be restrictive, but Discord does allow for deferring - a type of response that specifies Discord to show a loading/thinking state for up to 15 minutes while you prepare your actual response.
To do this, add this to the beginning of your command's code:

# First way
@interactions.slash_command(...)
async def slash_command(ctx):
  await ctx.defer()
  ...

# Second way
@interactions.slash_command(...)
@interactions.auto_defer(...)
async def slash_command_2(ctx):
  ...

If you wish for all of your commands to defer, then you can specify the auto_defer kwarg in your Client:

bot = Client(auto_defer=True, ...)

# If you want more control...
bot = Client(auto_defer=AutoDefer(...))
broken copper
#

Awesome, thanks !