Skip to content

Instantly share code, notes, and snippets.

@Andrew-9
Created July 14, 2020 08:44
Show Gist options
  • Save Andrew-9/2d005e2c874cef7ad609bd5ceb157c96 to your computer and use it in GitHub Desktop.
Save Andrew-9/2d005e2c874cef7ad609bd5ceb157c96 to your computer and use it in GitHub Desktop.
from discord.ext.commands import Cog
from discord.ext.commands import MissingPermissions
from discord.ext.commands import when_mentioned_or, command, has_permissions
from ..db import db
class Misc(Cog):
def __init__(self, bot):
self.bot = bot
@command(name="prefix", aliases=["pr"])
@has_permissions(manage_guild=True)
async def change_prefix(self, ctx, new: str):
if len(new) > 5:
await ctx.send("❌ The prefix cannot be more than 5 characters in length.")
else:
db.execute("UPDATE guilds SET Prefix = ? WHERE GuildID = ?", new, ctx.guild.id)
await ctx.send(f"✅ Prefix has been set to {new}")
@change_prefix.error
async def change_prefix_error(self, ctx, exc):
if isinstance(exc, MissingPermissions):
await ctx.send("❌ You need the manage server permissions to do that.")
@Cog.listener()
async def on_ready(self):
if not self.bot.ready:
self.bot.cogs_ready.ready_up("misc")
def setup(bot):
bot.add_cog(Misc(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment