diff --git a/cogs/induct.py b/cogs/induct.py index dd52a938..e718fd7d 100644 --- a/cogs/induct.py +++ b/cogs/induct.py @@ -179,7 +179,7 @@ async def get_random_welcome_message( async def _perform_induction( self, ctx: "TeXBotApplicationContext", - induction_member: discord.Member, + induction_member_id: int, *, silent: bool, ) -> None: @@ -188,6 +188,18 @@ async def _perform_induction( main_guild: discord.Guild = self.bot.main_guild guest_role: discord.Role = await self.bot.guest_role + induction_member: discord.Member | None = main_guild.get_member(induction_member_id) + if not induction_member: + await ctx.respond( + ( + ":information_source: No changes made. User cannot be inducted " + "because they have left the server " + ":information_source:" + ), + ephemeral=True, + ) + return + await ctx.defer(ephemeral=True) async with ctx.typing(): logger.debug("Inducting member %s, silent=%s", induction_member, silent) @@ -346,7 +358,7 @@ async def induct( await self.command_send_error(ctx, message=member_id_not_integer_error.args[0]) return - await self._perform_induction(ctx, induct_member, silent=silent) + await self._perform_induction(ctx, induct_member.id, silent=silent) class InductContextCommandsCog(BaseInductCog): @@ -356,7 +368,7 @@ class InductContextCommandsCog(BaseInductCog): @CommandChecks.check_interaction_user_has_committee_role @CommandChecks.check_interaction_user_in_main_guild async def non_silent_user_induct( - self, ctx: "TeXBotApplicationContext", member: discord.Member + self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User ) -> None: """ Definition & callback response of the "non_silent_induct" user-context-command. @@ -366,13 +378,13 @@ async def non_silent_user_induct( Therefore, it will induct a given member into your group's Discord guild by giving them the "Guest" role. """ - await self._perform_induction(ctx, member, silent=False) + await self._perform_induction(ctx, member.id, silent=False) @discord.user_command(name="Silently Induct User") @CommandChecks.check_interaction_user_has_committee_role @CommandChecks.check_interaction_user_in_main_guild async def silent_user_induct( - self, ctx: "TeXBotApplicationContext", member: discord.Member + self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User ) -> None: """ Definition & callback response of the "silent_induct" user-context-command. @@ -382,7 +394,7 @@ async def silent_user_induct( Therefore, it will induct a given member into your group's Discord guild by giving them the "Guest" role, only without broadcasting a welcome message. """ - await self._perform_induction(ctx, member, silent=True) + await self._perform_induction(ctx, member.id, silent=True) @discord.message_command(name="Induct Message Author") @CommandChecks.check_interaction_user_has_committee_role @@ -413,7 +425,7 @@ async def non_silent_message_induct( ) return - await self._perform_induction(ctx, member, silent=False) + await self._perform_induction(ctx, member.id, silent=False) class EnsureMembersInductedCommandCog(TeXBotBaseCog):