問題描述
我試圖讓我的 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 不和諧機器人的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!