My bot's custom custom prefix I used a json to stock all servers custom prefix. But when I try to launch the bot it gives me this error:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I typed in the file who stock prefixes (the json file) the
{
}
But it stills tell me the error here's the code for any helpers:
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)
@bot.event
async def on_guild_join(guild):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = "!"
with open("prefixes.json", "w") as f:
json.dump(prefixes,f)
@bot.command()
@commands.has_permissions(administrator = True)
async def prefix(ctx, prefix):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open("prefixes.json", "w") as f:
json.dump(prefixes,f)
await ctx.send(f"**The prefix was changed to `{prefix}`**")
print(f"i set the prefix for to {prefix}")
@bot.event
async def on_message(msg):
try:
if msg.mentions[0] == bot.user:
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
pre = prefixes[str(msg.guild.id)]
await msg.channel.send(f"My prefix for this server is `{pre}`")
except:
pass
await bot.process_commands(msg)