【发布时间】:2019-01-29 09:41:41
【问题描述】:
所以我有这段代码在不和谐机器人上运行,它应该重复用户在命令后所说的话。它这样做,但在通过该脚本总共运行 8 次后又重复了 7 次。谁能发现为什么会发生这种情况?
注意:实际运行的代码从 elif 开始,但我将所有内容都放入其中以防万一之前的东西弄乱了它。
@Client.event
async def on_message(message):
if message.content == "s!ping":
userID = message.author.id
Client.send_message(message.channel, "<@%s>" % (userID))
elif message.content.startswith == "s!say":
args = message.content.split(" ")
Client.send_message(message.channel, "%s" % (args[1:]))
【问题讨论】:
-
您可以尝试添加
if message.author == Client.user: return吗?另外,您使用的是什么版本的discord.py? -
所以我在 python 3.6.1 中使用 repli,我刚刚导入了 discord 库,我不知道如何检查它的版本。我会试试你的建议,谢谢你的帮助
-
您可以使用
import discord; print(discord.__version__)查看版本。我问的原因是因为discord.py的现代发行版应该要求你await那些Client.send_message(message.channel, "<@%s>" % (userID))调用 -
我使用的版本是0.16.12
标签: python python-3.x discord discord.py