【问题标题】:How come my bot won't realise the parameters?为什么我的机器人不会实现参数?
【发布时间】:2020-02-16 03:35:52
【问题描述】:

我有一个机器人,它应该在指挥时提供有关玩家的信息。命令是:

-Whois [USER]

然后机器人回复信息。

我输入 'iamonf1r3' 作为用户参数,它会得到 mip232 的响应。这是我的代码:

@client.command()
async def Whois(parameter):
    name = parameter
    if name == "mip232" or name == "Mip" or "219884374378676224":
        await client.say("Roblox Name: `mip232` \nDiscord Name: `Mip#3981` \nPin: `FS01` \nRank: `Chief Fire Officer` \nDivision: `All` \nActivity Level: `Active` \nDriving Level: `Advanced` \nDisciplinary Action: `None`")
    elif name == "iamonf1r3" or "iamonf1r3" or "335014153460776962":
        await client.say("Roblox Name: `iamonf1r3` \nDiscord Name: `iamonf1r3#7277` \nPin: `FS02` \nRank: `Deputy Chief Fire Officer` \nDivision: `All` \nActivity Level: `Active` \nDriving Level: `Advanced` \nDisciplinary Action: `None`")

【问题讨论】:

    标签: python discord discord.py python-asyncio


    【解决方案1】:

    您使用或使用方式错误

    说实话,你完全搞砸了你的“或状态”

    每个或必须有一个新的条件 右:

    if name == "mip232" or name == "Mip" or "219884374378676224":
    

    错误

    if name == "mip232" or name == "Mip" or name == "219884374378676224":
    

    你对你的 elif 做了同样的事情,但我会留给你来解决这个声明。

    解释: if <CONDITION> or <CONFITION>

    你在第一个条件中给的参数“name”没有给第二个or。

    另外,如果您问if name,它只会查看此变量是否存在 => 如果存在则为真,如果不存在则为假。

    所以你的最后一个or "219884374378676224" 基本上为 if 返回一个 True,因为 "219884374378676224" 存在,因为你只是在同一个块中初始化它,它不是一个查询。

    试试看这个:https://realpython.com/python-or-operator/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-25
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 2021-12-12
      • 2021-07-15
      相关资源
      最近更新 更多