当有人说出某个字词(两个字)时,discord bot relpys

im试图在py上创建不和谐的bot,而我对py还是新的

我试图让我的机器人在有人说出某个单词时回复

例如,如果sendace 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")

但是,如果我只说“不”,机器人会回复

有人可以帮助我吗?

lgl26 回答:当有人说出某个字词(两个字)时,discord bot relpys

您遇到的问题与机器人无关,这是Python的布尔值评估的工作方式。如果您运行orand之类的二进制运算符,则Python将返回确定其真值的第一件事。

对于x and y,如果False的计算结果为false,Python将返回x,如果x的计算结果为True,则Python将返回{{ 1}},因为它确定了y语句的真值。

鉴于非空字符串的求值为and,则示例中的输出将始终由第二个字符串确定。

True

因此,您的In [1]: True and 'bot' Out[1]: 'bot' In [2]: 'bot' and True Out[2]: True In [3]: 'bot' and 'not' Out[3]: 'not' In [4]: 'not' and 'bot' Out[4]: 'bot' 评估会给您"bot" and "not",并且漫游器将对其中带有单词“ not”的任何消息作出反应。

您需要更改条件以单独检查两个单词,并且仅在两个检查均通过时才做出反应

本文链接:https://www.f2er.com/2999698.html

大家都在问