From ede9168c9a011a1634247f6319dd8e4909576e50 Mon Sep 17 00:00:00 2001 From: neoarz Date: Mon, 22 Sep 2025 00:21:23 -0400 Subject: [PATCH] fix(sidestore & idevice): error handling for missing permissions --- .env.example | 2 +- cogs/idevice/idevice.py | 31 +++++++++++++++++++++++++------ cogs/sidestore/sidestore.py | 31 +++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 4a5c174..49b3f2b 100644 --- a/.env.example +++ b/.env.example @@ -3,4 +3,4 @@ PREFIX=YOUR_BOT_PREFIX_HERE INVITE_LINK=YOUR_BOT_INVITE_LINK_HERE # Commands you want to disable (comma separated) -DISABLED_COGS=general.context_menus # Context Menus +DISABLED_COGS=general.context_menus diff --git a/cogs/idevice/idevice.py b/cogs/idevice/idevice.py index b111619..d639a7d 100644 --- a/cogs/idevice/idevice.py +++ b/cogs/idevice/idevice.py @@ -21,13 +21,32 @@ class IdeviceSelect(discord.ui.Select): command = self.bot.get_command(command_name) if command: - ctx = await self.bot.get_context(interaction.message) - if ctx: - await ctx.invoke(command) + try: + ctx = await self.bot.get_context(interaction.message) + if ctx: + await ctx.invoke(command) + embed = discord.Embed( + title="Command Executed", + description=f"Successfully executed `/{command_name}`", + color=0x00FF00 + ) + embed.set_author(name="iDevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") + await interaction.response.edit_message(embed=embed, view=None) + except discord.Forbidden: + self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute {command_name} command") embed = discord.Embed( - title="Command Executed", - description=f"Successfully executed `/{command_name}`", - color=0x00FF00 + title="Permission Error", + description="The bot doesn't have the required permissions in this server to execute commands. Please contact a server administrator to add the bot to the server.", + color=0xFF0000 + ) + embed.set_author(name="iDevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") + await interaction.response.edit_message(embed=embed, view=None) + except Exception as e: + self.bot.logger.error(f"Error executing {command_name} command: {e}") + embed = discord.Embed( + title="Error", + description="An error occurred while executing the command.", + color=0xFF0000 ) embed.set_author(name="iDevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") await interaction.response.edit_message(embed=embed, view=None) diff --git a/cogs/sidestore/sidestore.py b/cogs/sidestore/sidestore.py index 4dc0413..2a13714 100644 --- a/cogs/sidestore/sidestore.py +++ b/cogs/sidestore/sidestore.py @@ -62,13 +62,32 @@ class SidestoreSelect(discord.ui.Select): command = self.bot.get_command(command_name) if command: - ctx = await self.bot.get_context(interaction.message) - if ctx: - await ctx.invoke(command) + try: + ctx = await self.bot.get_context(interaction.message) + if ctx: + await ctx.invoke(command) + embed = discord.Embed( + title="Command Executed", + description=f"Successfully executed `/{command_name}`", + color=0x00FF00 + ) + embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true") + await interaction.response.edit_message(embed=embed, view=None) + except discord.Forbidden: + self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute {command_name} command") embed = discord.Embed( - title="Command Executed", - description=f"Successfully executed `/{command_name}`", - color=0x00FF00 + title="Permission Error", + description="The bot doesn't have the required permissions in this server to execute commands. Please contact a server administrator to add the bot to the server.", + color=0xFF0000 + ) + embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true") + await interaction.response.edit_message(embed=embed, view=None) + except Exception as e: + self.bot.logger.error(f"Error executing {command_name} command: {e}") + embed = discord.Embed( + title="Error", + description="An error occurred while executing the command.", + color=0xFF0000 ) embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true") await interaction.response.edit_message(embed=embed, view=None)