这是我尝试过的代码:
@client.event
async def on_message(message):
if client.user.mention in message.content.split():
await client.say("You can type `!vx help` for more info.")
但是它似乎不起作用。
使用命令修饰符时,您可以执行以下操作:
from discord.ext import commands # necessary for this task
client = commands.Bot(command_prefix=commands.when_mentioned_or("!"))
或使用on_message()
事件,这是您可以检查提及的多种方法之一:
@client.event
async def on_message(message):
if client.user.mentioned_in(message):
await message.channel.send("You can type `!vx help` for more info")
而且,我注意到您向频道发送消息的方法不太正确。
在d.py重写(v1.x)中,您有一个abc.Messageable
对象,顾名思义,它类似于服务器的文本通道,DM或群聊。
并且此对象有一个称为send()
的方法,该方法使您可以发送内容。您会发现一些常见的情况;使用命令修饰符时,将ctx.send()
作为第一个参数,将Context
作为第一个参数;当您像使用“ C0”事件时,将其作为message.channel.send()
。它也会出现在其他一些地方,但这将是最常见的。
您对它是协程有了正确的想法,因此需要将其on_message()
。在文档中,它会指出某些东西是否是协程。
参考:
await
commands.when_mentioned_or()
commands.when_mentioned_or()
-查看可以向ClientUser.mentioned_in()
消息发送的内容。ClientUser.mentioned_in()
-这是从abc.Messageable
继承的。abc.Messageable