Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 制作discord bot时如何扫描完整消息?_Python_Python 3.x_Discord.py - Fatal编程技术网

Python 制作discord bot时如何扫描完整消息?

Python 制作discord bot时如何扫描完整消息?,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,虽然我遇到了一个问题,但我正试图制造一个不和谐的机器人。以下是默认代码: if message.content.startswith('hello'): 我想更改它,以便它扫描完整的消息,而不仅仅是开始。 我试过各种变体,但什么也没找到。有人能帮我吗? 提前感谢大家。解释 message.content是一个字符串变量,在该变量上保存完整的消息内容startswith是一种python字符串方法,它允许您检查给定字符串变量的开头 使用等于 通过此操作,您可以检查消息内容是否与特定文本相

虽然我遇到了一个问题,但我正试图制造一个不和谐的机器人。以下是默认代码:

    if message.content.startswith('hello'):
我想更改它,以便它扫描完整的消息,而不仅仅是开始。 我试过各种变体,但什么也没找到。有人能帮我吗? 提前感谢大家。

解释
message.content
是一个字符串变量,在该变量上保存完整的消息内容
startswith
是一种python字符串方法,它允许您检查给定字符串变量的开头

使用
等于
通过此操作,您可以检查消息内容是否与特定文本相同,并得出以下结论:

if message.content == 'hello':
在 另一个解决方案是检查消息中是否有“hello”:

if 'hello' in message.content:

你的意思是要扫描邮件的每一行,看看这一行是否以文本开头?要在
str
中检查自定义邮件,如果邮件中有“hello”,你可以这样做
。内容:
非常感谢大家!我在别的地方找不到这个。你们解决了我的问题。非常感谢。不客气!