1

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)
blackbishop
  • 30,945
  • 11
  • 55
  • 76
SIDAL
  • 13
  • 6
  • Does this answer your question? [JSONDecodeError: Expecting value: line 1 column 1 (char 0)](https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0) – Ulrich Eckhardt Dec 26 '21 at 18:03
  • Please search for the error message online before asking the same question as hundreds before you! – Ulrich Eckhardt Dec 26 '21 at 18:03

0 Answers0