我正在尝试做一些类似于为 Discord 注册 Python 聊天游戏的事情。我正在努力做到这一点,以便用户只能在其中注册一次。注册本身工作正常,但验证绝对不行。你能帮忙吗?
@bot.command()
async def getstart(ctx):
await ctx.send('placeholder (welcome message here)')
with open("config.json") as feedsjson:
feeds = json.load(feedsjson)
if not {"name": f"{ctx.message.author.id}"} in feeds:
await ctx.send('placeholder (we can add user in json file)..')
getstartinsocialcredit(ctx.message.author.id, 0)
else:
return await ctx.send('placeholder (user already in json file)')
应该是什么结果。用户注册一次,然后,如果他再次编写命令(比如 sc.getstart),那么机器人会写信给他:“你已经在基地!我不能再次添加你”,或类似的东西。
您的解决方案的问题是您将字典
{"name": f"{ctx.message.author.id}"}与进行比较{"name": 995336851030290462, "sc": 0},这永远不会相同,因为在第二种情况下,字典包含键“sc”。我可以建议这样做: