diff --git a/events/on_command_error.py b/events/on_command_error.py index 2481f59..adfcec2 100644 --- a/events/on_command_error.py +++ b/events/on_command_error.py @@ -205,26 +205,26 @@ async def on_command_error(self, ctx, error): color=BLANK_COLOR, ).set_footer(text=f"{error.code} | {error_id}") ) - with push_scope() as scope: - scope.set_tag("error_id", error_id) - scope.set_tag("guild_id", ctx.guild.id) - scope.set_tag("user_id", ctx.author.id) - if isinstance(ctx.bot, commands.AutoShardedBot): - scope.set_tag("shard_id", ctx.guild.shard_id) - scope.set_level("error") - await bot.errors.insert( - { - "_id": error_id, - "error": str(error), - "time": datetime.datetime.now(tz=pytz.UTC).strftime( - "%m/%d/%Y, %H:%M:%S" - ), - "channel": ctx.channel.id, - "guild": ctx.guild.id, - } - ) + with push_scope() as scope: + scope.set_tag("error_id", error_id) + scope.set_tag("guild_id", ctx.guild.id) + scope.set_tag("user_id", ctx.author.id) + if isinstance(ctx.bot, commands.AutoShardedBot): + scope.set_tag("shard_id", ctx.guild.shard_id) + scope.set_level("error") + await bot.errors.insert( + { + "_id": error_id, + "error": str(error), + "time": datetime.datetime.now(tz=pytz.UTC).strftime( + "%m/%d/%Y, %H:%M:%S" + ), + "channel": ctx.channel.id, + "guild": ctx.guild.id, + } + ) - capture_exception(error) + capture_exception(error) return if isinstance(error, commands.CheckFailure): diff --git a/menus.py b/menus.py index 493303f..62a67b8 100644 --- a/menus.py +++ b/menus.py @@ -5210,7 +5210,10 @@ async def on_timeout(self) -> None: i.disabled = True if not hasattr(self, "message") or not self.message: return - await self.message.edit(view=self) + try: + await self.message.edit(view=self) + except discord.HTTPException: + pass async def interaction_check(self, interaction: discord.Interaction, /) -> bool: if interaction.user.id == self.user_id: @@ -10039,16 +10042,25 @@ def __init__(self, bot, user_id: int, custom_callback: typing.Callable, args: li async def on_timeout(self) -> None: for item in self.children: item.disabled = True - await self.message.edit(view=self) + try: + await self.message.edit(view=self) + except discord.HTTPException: + pass async def _temp_disable(self, timer: int): for item in self.children: item.disabled = True - await self.message.edit(view=self) + try: + await self.message.edit(view=self) + except discord.HTTPException: + return await asyncio.sleep(timer) for item in self.children: item.disabled = False - await self.message.edit(view=self) + try: + await self.message.edit(view=self) + except discord.HTTPException: + pass async def interaction_check(self, interaction: discord.Interaction, /) -> bool: if interaction.user.id == self.user_id: @@ -11640,8 +11652,13 @@ async def erase_all_shifts( {"Guild": interaction.guild.id, "EndEpoch": 0} ): user_id = shift["UserID"] - member = interaction.guild.get_member(user_id) or await interaction.guild.fetch_member(user_id) - if member and member not in active_shift_users: + member = interaction.guild.get_member(user_id) + if not member: + try: + member = await interaction.guild.fetch_member(user_id) + except discord.NotFound: + continue + if member not in active_shift_users: active_shift_users.append(member) async for item in self.bot.shift_management.shifts.db.find( diff --git a/utils/autocompletes.py b/utils/autocompletes.py index 2341fab..a056ce0 100644 --- a/utils/autocompletes.py +++ b/utils/autocompletes.py @@ -14,6 +14,8 @@ async def shift_type_autocomplete( interaction: discord.Interaction, _: str ) -> typing.List[app_commands.Choice[str]]: bot = interaction.client + if not interaction.guild: + return [app_commands.Choice(name="Use this command in a server", value="none")] data = await bot.settings.find_by_id(interaction.guild.id) if not data: @@ -94,6 +96,9 @@ async def all_shift_type_autocomplete( interaction: discord.Interaction, _: str ) -> typing.List[app_commands.Choice[str]]: bot = (await Context.from_interaction(interaction)).bot + if not interaction.guild: + return [app_commands.Choice(name="Use this command in a server", value="none")] + data = await bot.settings.find_by_id(interaction.guild.id) if not data: return [app_commands.Choice(name="Default", value="Default")]