|
| 1 | +# Imports |
| 2 | +import discord |
| 3 | +from discord import option, ApplicationContext |
| 4 | +from discord.ext import commands |
| 5 | + |
| 6 | +# Commands |
| 7 | +class Moderation(commands.Cog): |
| 8 | + def __init__(self, bot): |
| 9 | + self.bot = bot |
| 10 | + |
| 11 | + @commands.slash_command( |
| 12 | + name='kick', |
| 13 | + description='Kicks a member from this server.' |
| 14 | + ) |
| 15 | + @option(name="user", description="Who do you want to kick?", type=discord.User) |
| 16 | + @option(name="reason", description="Why do you want to kick the user?", type=str, default=None) |
| 17 | + @commands.cooldown(1, 3, commands.BucketType.user) |
| 18 | + async def kick(self, ctx: ApplicationContext, user, reason=None): |
| 19 | + 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') |
| 20 | + else: |
| 21 | + try: |
| 22 | + if reason is None: await user.kick() |
| 23 | + else: await user.kick(reason=reason) |
| 24 | + await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}')) |
| 25 | + 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())) |
| 26 | + |
| 27 | + @commands.slash_command( |
| 28 | + name='ban', |
| 29 | + description='Bans a member from this server.' |
| 30 | + ) |
| 31 | + @option(name="user", description="Who do you want to ban?", type=discord.User) |
| 32 | + @option(name="reason", description="Why you want to ban the user?", type=str, default=None) |
| 33 | + @commands.cooldown(1, 3, commands.BucketType.user) |
| 34 | + async def ban(self, ctx: ApplicationContext, user, reason=None): |
| 35 | + if not ctx.author.guild_permissions.ban_members: return await ctx.respond('https://tenor.com/view/thor-strike-admin-ban-admin-ban-gif-22545175') |
| 36 | + else: |
| 37 | + try: |
| 38 | + if reason is None: await user.ban() |
| 39 | + else: await user.ban(reason=reason) |
| 40 | + await ctx.respond(embed=discord.Embed(title=f'{user} has been banned.', description=f'Reason: {str(reason)}')) |
| 41 | + 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())) |
| 42 | + |
| 43 | +# Initialization |
| 44 | +def setup(bot): bot.add_cog(Moderation(bot)) |
0 commit comments