diff --git a/cogs/make_applicant.py b/cogs/make_applicant.py index 619d7756..27e4e168 100644 --- a/cogs/make_applicant.py +++ b/cogs/make_applicant.py @@ -34,7 +34,7 @@ class BaseMakeApplicantCog(TeXBotBaseCog): """ async def _perform_make_applicant( - self, ctx: "TeXBotApplicationContext", applicant_member: discord.Member + self, ctx: "TeXBotApplicationContext", applicant_member_id: int ) -> None: """Perform the actual process of making the user into a group-applicant.""" # NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent @@ -42,6 +42,19 @@ async def _perform_make_applicant( applicant_role: discord.Role = await ctx.bot.applicant_role guest_role: discord.Role = await ctx.bot.guest_role + applicant_member: discord.Member | None = main_guild.get_member(applicant_member_id) + + if not applicant_member: + await ctx.respond( + content=( + ":information_source: " + "No changes made. User cannot be made into an applicant " + "because they have left the server :information_source:" + ), + ephemeral=True, + ) + return + if applicant_role in applicant_member.roles: await ctx.respond("User is already an applicant! Command aborted.") return @@ -196,7 +209,7 @@ async def make_applicant( await self.command_send_error(ctx, message=member_id_not_integer_error.args[0]) return - await self._perform_make_applicant(ctx, applicant_member) + await self._perform_make_applicant(ctx, applicant_member.id) class MakeApplicantContextCommandsCog(BaseMakeApplicantCog): @@ -206,7 +219,7 @@ class MakeApplicantContextCommandsCog(BaseMakeApplicantCog): @CommandChecks.check_interaction_user_has_committee_role @CommandChecks.check_interaction_user_in_main_guild async def user_make_applicant( - self, ctx: "TeXBotApplicationContext", member: discord.Member + self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User ) -> None: """ Definition and callback response of the "make_applicant" user-context-command. @@ -215,7 +228,7 @@ async def user_make_applicant( the "make_applicant" slash-command and thus gives the specified user the "Applicant" role and removes the "Guest" role if they have it. """ - await self._perform_make_applicant(ctx, member) + await self._perform_make_applicant(ctx, member.id) @discord.message_command(name="Make Message Author Applicant") @CommandChecks.check_interaction_user_has_committee_role @@ -230,19 +243,4 @@ async def message_make_applicant( the "make_applicant" slash-command and thus gives the specified user the "Applicant" role and removes the "Guest" role if they have it. """ - try: - member: discord.Member = await self.bot.get_member_from_str_id( - str(message.author.id) - ) - except ValueError: - await ctx.respond( - content=( - ":information_source: " - "No changes made. User cannot be made into an applicant " - "because they have left the server :information_source:" - ), - ephemeral=True, - ) - return - - await self._perform_make_applicant(ctx, member) + await self._perform_make_applicant(ctx, message.author.id) diff --git a/cogs/strike.py b/cogs/strike.py index 70bfcbe8..4cf0e08b 100644 --- a/cogs/strike.py +++ b/cogs/strike.py @@ -393,7 +393,7 @@ async def _confirm_increase_strike( ) async def _command_perform_strike( - self, ctx: "TeXBotApplicationContext", strike_member: discord.Member + self, ctx: "TeXBotApplicationContext", strike_member: discord.Member | discord.User ) -> None: """ Perform the actual process of giving a member an additional strike. @@ -1075,7 +1075,7 @@ async def _send_message_to_committee( @CommandChecks.check_interaction_user_has_committee_role @CommandChecks.check_interaction_user_in_main_guild async def user_strike( - self, ctx: "TeXBotApplicationContext", member: discord.Member + self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User ) -> None: """Call the _strike command, providing the required command arguments.""" await self._command_perform_strike(ctx, strike_member=member)