问题描述
我试图让我的 discord.py
机器人在有人发送一些单词时自动响应,但问题是该命令仅在单词是句子中要写的第一件事时才有效.即使单词在某个句子的中间,我也希望我的机器人响应消息.如果可以,我该怎么做?
I am trying to make my discord.py
bot respond automatically when someone sends some word, but the problem is that the command only works if the word is the first thing to be written in the sentence. I want my bot to respond the message even when the word is in the middle of some sentence. If this is possible, how can I do it?
推荐答案
下面的例子会做你想做的.
The following example will do what you want.
Bot = commands.Bot(command_prefix="")
@Bot.event
async def on_message(message):
if "not" in message.content:
await Bot.send_message(message.channel, 'yes')
为了澄清,message.content.startswith
只会检查定义的字符/字符串是否在消息的开头,而 message.content
会扫描已发送整条消息.
To clarify, message.content.startswith
will only check to see if the defined characters/string are at the start of the message, while message.content
scans the entire message sent.
这篇关于Python message.content 不和谐机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!