Извините, если я делаю эту часть кода неправильно, но я думаю, что учусь, как это сделатьВ любом случае, моя проблема в том, что я пытаюсь получить доступ к users.json (работал в прошлом), чтобы получить пользовательские монеты, однако мне нужно делать это в течение @ события, я полагаю, потому что мне нужна возможность доступа к переменной, которую я установил.json.load () тоже равный.Вот моя ошибка:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "/home/ubuntu/workspace/main/paeth.py", line 283, in on_reaction_add
users = json.load(f)
File "/usr/local/lib/python3.6/json/__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Ignoring exception in on_reaction_add
Если вы ищете код, который делает это возможным, вот @ client.event для on_reaction_add
@client.event
async def on_reaction_add(reaction, user):
with open('users.json', 'r') as f:
users = json.load(f)
global QUEUE
print(str(reaction.emoji))
if str(reaction.emoji) == "<:csgo:544232345620709376>":
role = discord.utils.get(user.server.roles, name="CS:GO")
await client.add_roles(user, role)
print("Added role CS:GO to user: " + str(user))
if str(reaction.emoji) == "<:overwatch:544232310896328739>":
role = discord.utils.get(user.server.roles, name="Overwatch")
await client.add_roles(user, role)
print("Added role Overwatch to user: " + str(user))
if str(reaction.emoji) == "<:apex:544232279325540359>":
role = discord.utils.get(user.server.roles, name="Apex Legends")
await client.add_roles(user, role)
print("Added role Apex Legends to user: " + str(user))
if str(reaction.emoji) == "<:cod:544232280374247453>":
role = discord.utils.get(user.server.roles, name="Call of Duty")
await client.add_roles(user, role)
print("Added role Call of Duty to user: " + str(user))
if str(reaction.emoji) == "<:fortnite:544232365313228800>":
role = discord.utils.get(user.server.roles, name="Fortnite")
await client.add_roles(user, role)
print("Added role Fortnite to user: " + str(user))
if str(reaction.emoji) == "✅":
print("User " + str(user) + " has just joined the queue.")
QUEUE.append(str(user))
if str(QUEUE[0]) == "PaethBot#1265":
QUEUE.remove(QUEUE[0])
else:
await client.send_message(user, "You have been added to the queue!")
print(QUEUE)
if str(reaction.emoji) == "?":
print("User " + str(user) + " has just attempted to join the bank heist")
if str(user) == "PaethBot#1265":
print("Removing Bot's Eligibility")
else:
tempCoins = users[user]['coins']
if tempCoins < joinIn:
await client.send_message(user, "Sorry, but your heist-mates saw that you didn't have enough coins to join them, and kicked you to the curb!")
else:
await client.send_message(user, "Congrats! Your heist-mates accepted your join request and took your " + str(joinIn) + " coins!")
await client.send_message(user, "Check in on the bankheist channel to see progress")
users[user]['coins'] -= int(joinIn)
HEIST.append(str(user))
with open('users.json', 'r') as f:
json.dump(users, f)
Здесь мои пользователи.json file: только что проверил, видимо пусто?Позвольте мне попытаться исправить.
Whole users.json:
{"265749200468180992": {"coins": 10}, "543968234685071370": {"coins": 0}}
Новая проблема заключается в том, что он продолжает стираться, вот мой код:
[Не могудобавьте его, потому что он слишком длинный, и я знаю, что вы, ребята, не любите хастебина]