From cad899532494ac72db010748e6a276170c872958 Mon Sep 17 00:00:00 2001 From: neoarz Date: Tue, 14 Apr 2026 16:34:03 -0400 Subject: [PATCH] fix: permission checking --- cogs/moderation/archive.py | 11 +++++++++++ cogs/moderation/hackban.py | 27 +++++++++++++++++++++++++++ cogs/moderation/purge.py | 22 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/cogs/moderation/archive.py b/cogs/moderation/archive.py index 5964b17..b3c5288 100644 --- a/cogs/moderation/archive.py +++ b/cogs/moderation/archive.py @@ -21,6 +21,17 @@ def archive_command(): :param context: The hybrid command context. :param limit: The limit of messages that should be archived. Default is 10. """ + if not context.author.guild_permissions.manage_messages: + embed = discord.Embed( + title="Missing Permissions!", + description="You are missing the permission(s) `manage_messages` to execute this command!", + color=0xE02B2B, + ).set_author( + name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png" + ) + await context.send(embed=embed, ephemeral=True) + return + log_file = f"{context.channel.id}.log" messages = [] diff --git a/cogs/moderation/hackban.py b/cogs/moderation/hackban.py index 52fe648..11b7881 100644 --- a/cogs/moderation/hackban.py +++ b/cogs/moderation/hackban.py @@ -23,6 +23,33 @@ def hackban_command(): :param reason: The reason for the ban. Default is "Not specified". """ try: + if ( + not context.author.guild_permissions.ban_members + and context.author != context.guild.owner + ): + embed = discord.Embed( + title="Missing Permissions!", + description="You don't have the `Ban Members` permission to use this command.", + color=0xE02B2B, + ).set_author( + name="Moderation", + icon_url="https://yes.nighty.works/raw/CPKHQd.png", + ) + await context.send(embed=embed, ephemeral=True) + return + + if not context.guild.me.guild_permissions.ban_members: + embed = discord.Embed( + title="Missing Permissions!", + description="I am missing the permission(s) `ban_members` to execute this command!", + color=0xE02B2B, + ).set_author( + name="Moderation", + icon_url="https://yes.nighty.works/raw/CPKHQd.png", + ) + await context.send(embed=embed, ephemeral=True) + return + await self.bot.http.ban(user_id, context.guild.id, reason=reason) user = self.bot.get_user(int(user_id)) or await self.bot.fetch_user( int(user_id) diff --git a/cogs/moderation/purge.py b/cogs/moderation/purge.py index 01734d4..f9055ea 100644 --- a/cogs/moderation/purge.py +++ b/cogs/moderation/purge.py @@ -15,6 +15,28 @@ def purge_command(): user="The user whose messages should be deleted (optional).", ) async def purge(self, context, amount: int, user: discord.Member = None): + if not context.author.guild_permissions.manage_messages: + embed = discord.Embed( + title="Missing Permissions!", + description="You are missing the permission(s) `manage_messages` to execute this command!", + color=0xE02B2B, + ).set_author( + name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png" + ) + await context.send(embed=embed, ephemeral=True) + return + + if not context.guild.me.guild_permissions.manage_messages: + embed = discord.Embed( + title="Missing Permissions!", + description="I am missing the permission(s) `manage_messages` to execute this command!", + color=0xE02B2B, + ).set_author( + name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png" + ) + await context.send(embed=embed, ephemeral=True) + return + if context.interaction: await context.defer(ephemeral=True)