Хочу сделать смену префикса бота командой, но получаю ошибку, сам код:
import discord
from discord.ext import commands
import os
import json
def get_prefix(bot, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
bot = commands.Bot(command_prefix=get_prefix, intents = discord.Intents.all())
@bot.event
async def on_ready():
print('Бот успешно запущен!')
#------------------------------------------------------------
@bot.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = 'cp.'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@bot.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop[str(guild.id)] = 'cp.'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@bot.command(aliases = ['prefix', 'refix'])
async def setprefix(ctx, prefixset):
if (not ctx.author.guild_permissions.manage_guild):
await ctx.send('Для этой команды требуются права **Управление сервером**')
return
if (prefixset == None):
prefixes = "cp."
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefixset
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
prefixes = discord.Embed(
title='Успешно!',
description=f'Вы изменили префикс бота на `{prefixset}`',
color=0x0c0c0c
)
await ctx.send(embed=embed)
Сама ошибка выглядит так:
Ignoring exception in on_guild_remove
Traceback (most recent call last):
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 31, in on_guild_remove
prefixes = json.load(f)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Буду благодарен за помощь.