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


基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01