Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.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 不和谐机器人当有人说某个词(两个词)时,机器人会反应_Python_Bots_Discord_Discord.py - Fatal编程技术网

Python 不和谐机器人当有人说某个词(两个词)时,机器人会反应

Python 不和谐机器人当有人说某个词(两个词)时,机器人会反应,python,bots,discord,discord.py,Python,Bots,Discord,Discord.py,我试图在py上制造一个不和谐的机器人,我是py的新手 当有人说某个词时,我正试图让机器人回答 例如,如果sentace bot中有“bot”和“not”,则用“您认为bot不工作吗?” 我做了这个密码 if message.content.find("bot" and "not") != -1: await message.channel.send("do you think bots aren't working? contact @sdu or ask other p

我试图在py上制造一个不和谐的机器人,我是py的新手

当有人说某个词时,我正试图让机器人回答

例如,如果sentace bot中有“bot”和“not”,则用“您认为bot不工作吗?” 我做了这个密码

    if message.content.find("bot" and "not") != -1:
        await message.channel.send("do you think bots aren't working? contact @sdu or ask other player in #bot channal")
        await message.channel.send("sorry for inconvenient")
但如果我只说“不”,机器人会回答


有人能帮我吗?

您遇到的问题与bot无关,而是Python的布尔求值方式。如果运行像
这样的二进制运算符,Python将返回确定其真值的第一个内容

对于
x和y
,如果
x
的计算结果为False,Python将返回
False
,如果
x
的计算结果为
True
,Python将返回
y
的值,因为这将确定
语句的真值

假设非空字符串的计算结果为
True
,则示例中的输出将始终由第二个字符串确定

[1]中的
:True和'bot'
Out[1]:“bot”
在[2]中:“bot”和True
Out[2]:正确
在[3]中:“bot”和“not”
Out[3]:“不是”
在[4]中:'not'和'bot'
Out[4]:“bot”
因此,您的
“bot”和“not”
评估将为您提供
“not”
,bot将对其中包含“not”一词的任何消息作出反应

您需要更改您的条件以分别检查这两个单词,并且仅当两个检查都通过时才作出反应