from disnake.ext import commands DEFAULT_PREFIX = '!' async def getprefix(ctx, message): if not message.guild: return commands.when_mentioned_or(DEFAULT_PREFIX)(ctx, message) prefix = await ctx.db.fetch('SELECT prefix FROM prefixes WHERE guild_id = $1', message.guild.id) if len(prefix) == 0: await ctx.db.execute('INSERT INTO prefixes(guild_id, prefix) VALUES ($1, $2)', message.guild.id, DEFAULT_PREFIX) prefix = DEFAULT_PREFIX else: prefix = prefix[0].get("prefix") return commands.when_mentioned_or(prefix)(ctx, message) class Prefix(commands.Cog): def __init__(self, bot): self.bot = bot @commands.command(pass_context=True) @commands.has_permissions(administrator=True) async def setprefix(ctx, newprefix): await ctx.db.execute('UPDATE prefixes SET prefix = $1 WHERE guild_id = $2', newprefix, ctx.guild.id) await ctx.send(f"Updated to prefix `{newprefix}` by {ctx.author.mention}!") @setprefix.error async def setprefix_error(self, ctx, error): if isinstance(error, commands.MissingPermissions): await ctx.send("You can't do that!") def setup(bot): bot.add_cog(Prefix(bot))