简体   繁体   中英

pycord bot quits slash command too quick

When my bot is very busy, it sometimes takes a few seconds to respond to the slash commands. However, before he can reply, Discord sends the message "The application did not respond". How can I make Discord wait longer for a message from the bot?

Have you tried using Interaction.defer() ? Here's a quick example on how to use that:

@bot_instance.slash_command(name="hi")
async def hi(ctx):
   await ctx.defer()
   # fairly long task?
   await ctx.followup.send( # Whatever you want to send...

For more information check out the API Reference: https://docs.pycord.dev/en/master/api.html#discord.Interaction

Also see a GitHub issue related to this question: https://github.com/Pycord-Development/pycord/issues/264

There is something called defer, you can do that to increase waiting time of the function

@bot_instance.command(description="Description of the command"
async def command(ctx:discord.Interaction,keyword:str)#Keyword if any
     await ctx.response.defer(ephemeral=True)#This line defers the function
     #Do your process here
     await ctx.followup("Followup message")#This is the confirmation message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM