问题描述
我试图让我的 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)