[英]check if item is on the list discord python
我有一个我无法弄清楚的问题。 我在 python 中做一个 discord 机器人。 我有一个 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 结果。 这让我想知道这段代码有什么问题。 我输入了我知道在列表中的数字,但它始终显示不在列表中。 当我在其他使用 for i in range(len(usual_suspects)): 的命令中使用此列表时,它工作正常。
我应该以不同的方式解决这个问题,还是只是我不知道的一些错误? 谢谢你!
由于根据提供的信息很难确定,这里有一个可能的情况。 arg
可能作为string
传入。 如果您所说的usual suspects
列表中有整数,请确保首先将其转换为int
。 修改您的代码,如下所示: int(arg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.