def get_prefix(bot, message):
with open("prefixDB.json", "r") as f:
prefix = json.load(f)
return prefix[str(message.guild.id)]
bot = commands.Bot(command_prefix = commands.when_mentioned_or(get_prefix), help_command = None)
bot.remove_command("help")
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 979, in on_message
await self.process_commands(message)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 975, in process_commands
ctx = await self.get_context(message)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 909, in get_context
raise TypeError("Iterable command_prefix or list returned from get_prefix must "
TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not function
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)