Python message.content 不和谐机器人

Luc*_*sch 4 python bots discord discord.py

我试图让我的discord.py 机器人在有人发送一些单词时自动响应,但问题是该命令仅在该单词是句子中第一个写入的情况下才有效。我希望我的机器人能够响应该消息,即使该单词位于某个句子的中间。如果这是可能的,我该怎么做?

小智 5

以下示例将执行您想要的操作。

Bot = commands.Bot(command_prefix="")

@Bot.event

async def on_message(message):

     if "not" in message.content:
           await Bot.send_message(message.channel, 'yes')
Run Code Online (Sandbox Code Playgroud)

为了澄清,message.content.startswith只会检查定义的字符/字符串是否位于消息的开头,同时message.content扫描发送的整个消息。