From 10d145a368a26f3dfefe367202c8122b7e951294 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 31 Mar 2023 22:01:13 +0530 Subject: [PATCH] Move existing moderation commands to new cog Includes only `/kick` and `/ban` commands. --- cogs/moderation.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.py | 45 +++++++-------------------------------------- 2 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 cogs/moderation.py diff --git a/cogs/moderation.py b/cogs/moderation.py new file mode 100644 index 00000000..e1e87c16 --- /dev/null +++ b/cogs/moderation.py @@ -0,0 +1,44 @@ +# Imports +import discord +from discord import option, ApplicationContext +from discord.ext import commands + +# Commands +class Moderation(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.slash_command( + name='kick', + description='Kicks a member from this server.' + ) + @option(name="user", description="Who do you want to kick?", type=discord.User) + @option(name="reason", description="Why do you want to kick the user?", type=str, default=None) + @commands.cooldown(1, 3, commands.BucketType.user) + async def kick(self, ctx: ApplicationContext, user, reason=None): + if not ctx.author.guild_permissions.kick_members: return await ctx.respond('https://tenor.com/view/oh-yeah-high-kick-take-down-fight-gif-14272509') + else: + try: + if reason is None: await user.kick() + else: await user.kick(reason=reason) + await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}')) + except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red())) + + @commands.slash_command( + name='ban', + description='Bans a member from this server.' + ) + @option(name="user", description="Who do you want to ban?", type=discord.User) + @option(name="reason", description="Why you want to ban the user?", type=str, default=None) + @commands.cooldown(1, 3, commands.BucketType.user) + async def ban(self, ctx: ApplicationContext, user, reason=None): + if not ctx.author.guild_permissions.ban_members: return await ctx.respond('https://tenor.com/view/thor-strike-admin-ban-admin-ban-gif-22545175') + else: + try: + if reason is None: await user.ban() + else: await user.ban(reason=reason) + await ctx.respond(embed=discord.Embed(title=f'{user} has been banned.', description=f'Reason: {str(reason)}')) + except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red())) + +# Initialization +def setup(bot): bot.add_cog(Moderation(bot)) diff --git a/main.py b/main.py index 15c5c5a6..aab78e50 100644 --- a/main.py +++ b/main.py @@ -224,38 +224,6 @@ async def sync(ctx: ApplicationContext): print(e) await ctx.respond('An error occured while resyncing. Check console.', ephemeral=True) -@client.slash_command( - name='kick', - description='Kicks a member from this server.' -) -@option(name="user", description="Who do you want to kick?", type=discord.User) -@option(name="reason", description="Why do you want to kick the user?", type=str, default=None) -@commands.cooldown(1, 3, commands.BucketType.user) -async def kick(ctx: ApplicationContext, user, reason=None): - if not ctx.author.guild_permissions.kick_members: return await ctx.respond('https://tenor.com/view/oh-yeah-high-kick-take-down-fight-gif-14272509') - else: - try: - if reason is None: await user.kick() - else: await user.kick(reason=reason) - await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}')) - except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red())) - -@client.slash_command( - name='ban', - description='Bans a member from this server.' -) -@option(name="user", description="Who do you want to ban?", type=discord.User) -@option(name="reason", description="Why you want to ban the user?", type=str, default=None) -@commands.cooldown(1, 3, commands.BucketType.user) -async def ban(ctx: ApplicationContext, user, reason=None): - if not ctx.author.guild_permissions.ban_members: return await ctx.respond('https://tenor.com/view/thor-strike-admin-ban-admin-ban-gif-22545175') - else: - try: - if reason is None: await user.ban() - else: await user.ban(reason=reason) - await ctx.respond(embed=discord.Embed(title=f'{user} has been banned.', description=f'Reason: {str(reason)}')) - except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red())) - # Cog Commands (these cannot be moved into a cog) cogs = client.create_group("cog", "Commands for working with isobot cogs.") @@ -318,13 +286,14 @@ async def reload(ctx: ApplicationContext, cog: str): # Initialization active_cogs = [ - "economy", + "economy", "maths", - "reddit", - "minigames", - "automod", - "isobank", - "levelling", + "reddit", + "moderation", + "minigames", + "automod", + "isobank", + "levelling", "fun", "utils", "afk"