问题描述
当这段代码运行时,它可以从 discord 中获取用户 ID,并将他们有 100 钱放入 json,但是一旦你重新启动机器人,你必须再次注册,它会在 json 文件中写入相同的用户 ID,认为这是一个如果不是新用户.
When this code runs it works getting the user ID from discord and putting they have 100 money in the json, but once you restart the bot you have to register again and it writes the same user ID in the json file thinking it's a new user when it is not.
机器人关闭并重新打开并注册两次后的 JSON(假用户 ID):
JSON after the bot is turned off and back on and registered twice (fake user IDs):
即使在机器人关闭并重新打开后也需要它能够识别用户 ID.
Need it to be able to recognize the user IDs even after the bot is turned off and back on.
推荐答案
发生这种情况是因为 JSON 对象总是有键"的字符串.所以 json.dump
将整数键转换为字符串.您可以通过在使用用户 ID 之前将其转换为字符串来执行相同的操作.
This is happening because JSON objects always have strings for the "keys". So json.dump
converts the integer keys to strings. You can do the same by converting the user ids to strings before you use them.
这篇关于Discord money bot 将用户 ID 保存在 json 文件中.当 Bot 重新启动时,它会为每个人创建一个新的(但相同的)ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!