def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
client = commands.Bot(command_prefix = get_prefix, intents = discord.Intents.all())
client.remove_command('help')
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = 't.'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, 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)] = 't.'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command(aliases = ['prefix', 'refix'])
async def setprefix(ctx, prefixset):
if (not ctx.author.guild_permissions.manage_guild):
await ctx.send('Для этой команды требуются права **Управление сервером**')
return
if (prefixset == None):
prefixset = 't.'
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)
prefix = discord.Embed(description = f'Вы изменили префикс бота на `{prefixset}`', color = discord.Colour.random())
await ctx.send(embed = prefix)