pycord机器人退出slash命令太快



当我的机器人非常忙时,有时需要几秒钟才能响应斜杠命令。然而,在他回复之前,Discord发送了一条消息"应用程序没有响应";。如何让Discord等待来自机器人的消息的时间更长?

您尝试过使用Interaction.defer()吗?这里有一个关于如何使用的快速示例:

@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...

有关更多信息,请参阅API参考:https://docs.pycord.dev/en/master/api.html#discord.Interaction

另请参阅与此问题相关的GitHub问题:https://github.com/Pycord-Development/pycord/issues/264

有一种叫做defer的东西,你可以这样做来增加函数的等待时间

@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

最新更新