@@ -94,7 +94,7 @@ class ConfirmStrikeMemberView(View):
9494 @discord .ui .button (
9595 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_strike_member"
9696 )
97- async def yes_strike_member_button_callback ( # type: ignore[misc]
97+ async def yes_strike_member_button_callback (
9898 self , _ : discord .Button , interaction : discord .Interaction
9999 ) -> None :
100100 """
@@ -113,7 +113,7 @@ async def yes_strike_member_button_callback( # type: ignore[misc]
113113 @discord .ui .button (
114114 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_strike_member"
115115 )
116- async def no_strike_member_button_callback ( # type: ignore[misc]
116+ async def no_strike_member_button_callback (
117117 self , _ : discord .Button , interaction : discord .Interaction
118118 ) -> None :
119119 """
@@ -136,7 +136,7 @@ class ConfirmManualModerationView(View):
136136 @discord .ui .button (
137137 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_manual_moderation_action"
138138 )
139- async def yes_manual_moderation_action_button_callback ( # type: ignore[misc]
139+ async def yes_manual_moderation_action_button_callback (
140140 self , _ : discord .Button , interaction : discord .Interaction
141141 ) -> None :
142142 """
@@ -156,7 +156,7 @@ async def yes_manual_moderation_action_button_callback( # type: ignore[misc]
156156 @discord .ui .button (
157157 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_manual_moderation_action"
158158 )
159- async def no_manual_moderation_action_button_callback ( # type: ignore[misc]
159+ async def no_manual_moderation_action_button_callback (
160160 self , _ : discord .Button , interaction : discord .Interaction
161161 ) -> None :
162162 """
@@ -180,7 +180,7 @@ class ConfirmStrikesOutOfSyncWithBanView(View):
180180 @discord .ui .button (
181181 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_out_of_sync_ban_member"
182182 )
183- async def yes_out_of_sync_ban_member_button_callback ( # type: ignore[misc]
183+ async def yes_out_of_sync_ban_member_button_callback (
184184 self , _ : discord .Button , interaction : discord .Interaction
185185 ) -> None :
186186 """
@@ -200,7 +200,7 @@ async def yes_out_of_sync_ban_member_button_callback( # type: ignore[misc]
200200 @discord .ui .button (
201201 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_out_of_sync_ban_member"
202202 )
203- async def no_out_of_sync_ban_member_button_callback ( # type: ignore[misc]
203+ async def no_out_of_sync_ban_member_button_callback (
204204 self , _ : discord .Button , interaction : discord .Interaction
205205 ) -> None :
206206 """
@@ -264,7 +264,7 @@ async def _send_strike_user_message(
264264 async def _confirm_perform_moderation_action (
265265 self ,
266266 message_sender_component : "MessageSavingSenderComponent" ,
267- interaction_user : discord .User ,
267+ interaction_user : discord .User | discord . Member ,
268268 strike_user : discord .Member ,
269269 confirm_strike_message : str ,
270270 actual_strike_amount : int ,
@@ -315,7 +315,7 @@ async def _confirm_perform_moderation_action(
315315 async def _confirm_increase_strike (
316316 self ,
317317 message_sender_component : "MessageSavingSenderComponent" ,
318- interaction_user : discord .User ,
318+ interaction_user : discord .User | discord . Member ,
319319 strike_user : discord .User | discord .Member ,
320320 member_strikes : DiscordMemberStrikes ,
321321 button_callback_channel : discord .TextChannel | discord .DMChannel ,
@@ -401,6 +401,12 @@ async def _command_perform_strike(
401401 Also calls the process of performing the appropriate moderation action,
402402 given the new number of strikes that the member has.
403403 """
404+ if not isinstance (ctx .channel , (discord .TextChannel , discord .DMChannel )):
405+ await self .command_send_error (
406+ ctx , message = "This command can only be used in text channels or DMs."
407+ )
408+ return
409+
404410 if strike_member .bot :
405411 await self .command_send_error (
406412 ctx ,
@@ -504,8 +510,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915
504510 async for _audit_log_entry in main_guild .audit_logs (
505511 after = discord .utils .utcnow () - datetime .timedelta (minutes = 1 ), action = action
506512 )
507- if _audit_log_entry .target .id
508- == strike_user .id # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
513+ if _audit_log_entry .target and _audit_log_entry .target .id == strike_user .id # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
509514 )
510515 except (StopIteration , StopAsyncIteration ):
511516 logger .debug ("Printing 5 most recent audit logs:" )
@@ -750,10 +755,7 @@ async def on_member_update(self, before: discord.Member, after: discord.Member)
750755
751756 audit_log_entry : discord .AuditLogEntry
752757 async for audit_log_entry in main_guild .audit_logs (limit = 5 ):
753- FOUND_CORRECT_AUDIT_LOG_ENTRY : bool = audit_log_entry .target .id == after .id and (
754- audit_log_entry .action
755- == discord .AuditLogAction .auto_moderation_user_communication_disabled
756- )
758+ FOUND_CORRECT_AUDIT_LOG_ENTRY : bool = ((audit_log_entry .target is not None ) and (audit_log_entry .target .id == after .id ) and (audit_log_entry .action == discord .AuditLogAction .auto_moderation_user_communication_disabled ))
757759 if FOUND_CORRECT_AUDIT_LOG_ENTRY :
758760 await self ._confirm_manual_add_strike (
759761 strike_user = after , action = audit_log_entry .action
0 commit comments