Я делаю систему выравнивания для моего бота Discord в discord.py (python 3.6.8), но я продолжаю получать эту ошибку, и я не могу понять, что это значит.
Вот мой код:
import random, asyncio, os, discord, json, time
from discord.ext.commands import Bot
BOT_PREFIX = ("&")
client = Bot(command_prefix=BOT_PREFIX)
client.remove_command('help')
if not os.path.exists('users.json'):
open('users.json', 'w').close()
@client.event
async def on_message(message):
with open("users.json", "r") as f:
users = json.load(f)
if message.author.bot:
return
if message.channel.is_private:
return
else:
await update_data(users, message.author, message.server)
number = random.randint(5,10)
await add_experience(users, message.author, number, message.server)
await level_up(users, message.author, message.channel, message.server)
with open("users.json", "w") as f:
json.dump(users, f)
await client.process_commands(message)
async def update_data(users, user, server):
if not user.id + "-" + server.id in users:
users[user.id + "-" + server.id] = {}
users[user.id + "-" + server.id]["experience"] = 0
users[user.id + "-" + server.id]["level"] = 0
users[user.id + "-" + server.id]["last_message"] = 0
async def add_experience(users, user, exp, server):
if time.time() - users[user.id + "-" + server.id]["last_message"] > 5:
users[user.id + "-" + server.id]["experience"] += exp
users[user.id + "-" + server.id]["last_message"] = time.time()
else:
return
async def level_up(users, user, channel, server):
experience = users[user.id + "-" + server.id]["experience"]
lvl_start = users[user.id + "-" + server.id]["level"]
lvl_end = int(experience ** (1/4))
if lvl_start < lvl_end:
await client.send_message(channel, f"{user.mention}, has leveled up to level {lvl_end}!")
users[user.id + "-" + server.id]["level"] = lvl_end
print('[BOT SUCCESSFULLY STARTED]\n\n')
client.run('YOUR_TOKEN_HERE')
Вот моя ошибка:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\NeverEndingCycle\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:\Users\NeverEndingCycle\Desktop\Coding_Stuff\Py_Code\Bot_Testing\Logic_Tests\XP-Logic\main.py", line 14, in on_message
users = json.load(f)
File "C:\Users\NeverEndingCycle\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\Users\NeverEndingCycle\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\NeverEndingCycle\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\NeverEndingCycle\AppData\Local\Programs\Python\Python36\lib\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)
Редактировать: Эта проблема была решена, пожалуйста, проверьте мой ответ ниже, если у вас возникла та же проблема.