Python message.content不和谐机器人 [英] Python message.content discord bot

查看:81
本文介绍了Python message.content不和谐机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个帮助,我试图让我的机器人在有人写下某个单词时自动做出响应,问题是该命令仅在单词是句子中第一要写的单词时才有效.我希望我的机器人即使在某个句子的中间单词时也可以响应该消息.我该怎么办?

I would like a help, I am trying to make my bot in discord to respond automatically when someone writes some word, the problem is that the command only works if the word is the first thing to be written in the sentence. I wish my bot could respond to the message even when the word is in the middle of some sentence. What should I do?

推荐答案

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不和谐机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆