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 不和谐机器人


基础教程推荐
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01