Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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.py message.content.find多个单词_Python_Discord.py - Fatal编程技术网

Python Discord.py message.content.find多个单词

Python Discord.py message.content.find多个单词,python,discord.py,Python,Discord.py,简单的问题,可能不是那么简单的答案。我能让机器人回答更多的单词,而不仅仅是“嗨”吗?例如,message.content.find将有多个字来执行事件 代码如下: @client.event async def on_message(message): if message.content.find("Hi") >= 0: channel = message.channel await message.channel.send(

简单的问题,可能不是那么简单的答案。我能让机器人回答更多的单词,而不仅仅是“嗨”吗?例如,
message.content.find
将有多个字来执行事件

代码如下:

@client.event
async def on_message(message):

    if message.content.find("Hi") >= 0:
        channel = message.channel
        await message.channel.send("Hello!")

        def check(m):
            return m.content != "x" and m.channel == channel

        msg = await client.wait_for("message", check=check)
        await message.channel.send("How are you?".format(msg))

您还可以使用语法检查另一个字符串中是否有某个字符串

而不是使用:

如果message.content.find(“Hi There”)>=0:
您可以使用:

如果message.content中有“Hi There”:

让你惊讶的是,答案其实很简单

如果message.content中的“hi”:
#你的密码在这里
现在,有了这个,我们有一个问题。如果用户说“嗨,我是komko”,它会触发事件,但“嗨,我是komko”不会。为什么?嗯,我们正在检查message.content中的“hi”,而不是“hi”或“hi”,等等

我的方法是使用
lower()

现在看来:

#我们还可以在前面声明一个字符串,如:
stringValue=“HI”
如果message.content.lower()中的stringValue.lower():
#你的密码在这里
这也可以替换为:

如果message.content.lower()中的“Hi”.lower():
#你的密码在这里
“我可以”嗯,当你尝试做最明显的事情时发生了什么?喜欢“
message.content.find
将有多个单词”当您尝试将多个单词放在那里时发生了什么?