Custom server prefix error bot

Solution for Custom server prefix error bot
is Given Below:

If i want to run the code and enter in my discord server +prefix ! comes the following error message:

line 13, in get_prefix
return prefixes[str(]
KeyError: ‘848927731752239108’

import discord
from discord.ext import commands
import asyncio
import random
import json

def get_prefix(client,message):

    with open("prefixes.json", "r") as f:
        prefixes = json.load(f)
    return prefixes[str(]

What does this error mean and how can i fix this?


This error means that id is not in the dictionary of ids and prefixs.

To fix this make sure your bot will automatically add servers to the list with a default prefix. There’s a great youtube video on that here:

Have a great day!