【发布时间】:2019-09-25 18:55:42
【问题描述】:
在我的 discord bot 中,我正在处理一个命令,您可以在其中执行类似 !command 的操作,然后该 bot 回复“执行命令?[y/n]”并听您说“y”,然后执行某物。我正在尝试向此函数添加超时,但我无法捕捉到此超时何时发生并触发事件,例如当超时发生时,机器人说“确认超时”。并继续。
我已经尝试过elif userinput is None: 和elif userinput is '':,两者都没有触发。
我在 Raspbian 拉伸上使用 discord.py 0.16.12 和 Python 3.6.1。
这是我目前拥有的:
msgconfirm = await client.say(f"[{context.message.author.mention}] Confirm? [y/n]")
userinput = await client.wait_for_message(timeout=5, author=context.message.author)
if userinput.clean_content.lower() == 'y':
do something
elif userinput is None:
do something
else:
do something
目前,当超时触发时,它只是忽略我发送的下一条消息,但不会触发elif userinput is None:。我正在寻找它来触发该块,所以我可以添加类似await client.say(f"[{context.message.author.mention}] Confirmation timed out.
我已经尝试使用this 页面上的答案,但它们都不起作用。该页面上的代码格式也不正确。
【问题讨论】:
标签: python-3.x discord discord.py