我有一个长时间运行的功能,大约需要20秒左右才能完成。函数完成后,它将结果作为消息发送给Discord
如果我通过输入一个常用命令(没有斜杠命令)来运行这个函数,它会完全正常工作,并且我会看到结果发送到Discord
但是,如果我通过斜杠命令调用函数,Discord会告诉我“此交互失败”,然后在消息中看到结果后不久。因此,该函数工作得非常好,但斜杠命令似乎认为它们失败了
为了测试这一点,我得到了一个基本函数:
@slash.slash(name="test",
guild_ids=[123,456],
description="This is just a test command, nothing more.",
options=[
create_option(
name="optone",
description="This is the first option we have.",
option_type=3,
required=False
)
])
async def test(ctx, optone: str):
await ctx.send(content=f"I got you, you said {optone}!")
如果我通过斜杠命令调用它,没有问题。然后我在await ctx.send...
上放置一个断点,然后再次运行该命令。Discord说“这种互动失败了”。我继续调试执行,然后发送消息
为什么斜杠命令认为命令失败了,而它没有失败,我该如何修复它
您应该包括您的软件包使用的斜杠命令,但是(从命令语法来看)我假设您使用的是discord-py-slash-command
从package和discord's developer文档中:
将ctx.defer()添加到命令的顶部。 如果您需要的时间超过15秒,您可以发送一条消息,稍后再进行编辑
相关问题 更多 >
编程相关推荐