I tried these code
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(float)
return prefixes[str(message.guild.id)]
client = commands.Bot(command_prefix = get_prefix)
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(float)
prefixes[str(guild.id)] = ','
with open('prefixes.json', 'w') as f:
json.dump(prefixes, float, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as float:
json.dump(prefixes, float, indent=4)
@client.command()
@commands.has_permissions(manage_channels=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, indent=4)
await ctx.send(f'Prefix changed succesfully, now my prefix for this server is: "{prefix}"')
and i got these erors
Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", >line 312, in _run_event await coro(*args, **kwargs) File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 943, in on_message await self.process_commands(message) File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in process_commands ctx = await self.get_context(message) File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 853, in get_context prefix = await self.get_prefix(message) File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 798, in get_prefix ret = await discord.utils.maybe_coroutine(prefix, self, message) File "C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\utils.py", line >331, in maybe_coroutine value = f(*args, **kwargs) File "C:\Users\PC\Desktop\Code\Project 01\index.py", line 20, in get_prefix return prefixes[str(message.guild.id)] KeyError: '744103149471662152'
Please help, it was working a few weeks ago.
json.load(float)
andjson.dump(.., float,..)
do? Did you meanf
? – L D