Python message.content discord bot(Python message.content 不和谐机器人)
问题描述
我试图让我的 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 不和谐机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python message.content 不和谐机器人
基础教程推荐
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
