首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pycord太快地退出斜杠命令。

pycord太快地退出斜杠命令。
EN

Stack Overflow用户
提问于 2022-02-28 15:04:25
回答 2查看 1.3K关注 0票数 1

当我的机器人非常忙时,有时需要几秒钟才能响应斜杠命令。然而,在他回复之前,不和谐会发出“应用程序没有响应”的信息。我怎么能让争吵等得更久才能收到机器人的信息呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-02-28 16:45:37

你试过使用Interaction.defer()吗?下面是一个关于如何使用它的快速示例:

代码语言:javascript
复制
@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

票数 1
EN

Stack Overflow用户

发布于 2022-06-20 03:54:41

有一种叫做延迟的方法,您可以这样做来增加函数的等待时间。

代码语言:javascript
复制
@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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71296971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档