【发布时间】:2020-08-02 09:10:38
【问题描述】:
所以我试图在 discord.py 中创建一个事件,每当用户提及/ping 机器人时,它都会说些什么。下面的代码运行没有错误,但唯一可行的方法是我的命令前缀在消息中。
对于我的机器人,前缀是“/”,所以每当我在消息中提到带有“/”的机器人时,它都会说些什么。如果我决定只提及机器人,机器人不会响应。我很确定这与最后一行代码有关,但我不知道如何解决这个问题。
@client.event
async def on_message(message):
if client.user.mention in message.content.split():
await message.channel.send('You mentioned me!')
else:
await client.process_commands(message)
代码是用 Python 3.7.4 编写的。
所有帮助将不胜感激!
【问题讨论】:
-
看起来机器人只会处理未提及的命令。您可能希望将
process_commands移出else -
@PatrickHaugh 我很确定我以前做过,我删除了
else并且发生了同样的结果。 (“/@botname”有效,但“@botname”无效)
标签: python python-3.x discord python-3.7 discord.py