【发布时间】:2022-06-20 11:54:41
【问题描述】:
当我的机器人很忙时,有时需要几秒钟来响应斜杠命令。然而,在他回复之前,Discord 发送了消息“应用程序没有响应”。如何让 Discord 等待来自机器人的消息的时间更长?
【问题讨论】:
-
我已经回答了您的问题,但是您可以将您的代码放在问题中吗?谢谢!
当我的机器人很忙时,有时需要几秒钟来响应斜杠命令。然而,在他回复之前,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
【讨论】: