【问题标题】:check if item is on the list discord python检查项目是否在列表中 discord python
【发布时间】:2021-06-25 22:54:03
【问题描述】:

我有一个我无法解决的问题。我在 python 中做一个不和谐的机器人。 我有一个 ghost_list.py (单独的文件),它有通常的嫌疑人 =[500 个数字在这里分隔,]

from ghost_list import usual_suspects

@bot.command()

async def isidonlist(ctx, arg):

    if arg in usual_suspects:
        nameget = opener.open(f"{api_url}{theme}/{arg}?selections=&key= 
        {api_key}").read()
        namegetdata = json.loads(nameget)
        ghost_name = (namegetdata['name'])
        await ctx.send(f"{ghost_name} is on the list of usual suspects.")

    else:
        await ctx.send(f"{arg} is NOT on the list of usual suspects.")

现在的问题是我总是得到 else 结果。这让我想知道这段代码有什么问题。我输入了我知道在列表中的数字,但它始终显示不在列表中。 当我在其他使用的命令中使用此列表时 对于我在范围内(len(usual_suspects)): 它工作正常。

我应该以不同的方式解决这个问题,还是只是我不知道的一些错误? 谢谢!

【问题讨论】:

    标签: python list discord


    【解决方案1】:

    由于根据提供的信息很难确定,这里有一个可能的情况。 arg 可能会作为 string 传入。确保首先将其转换为int,如果您的usual suspects 列表中有整数,如您所说。修改您的代码,如下所示:int(arg)

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 2012-06-30
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多