@@ -334,22 +334,36 @@ async def on_error(
334334 else :
335335 log .exception (type (error ).__name__ , exc_info = error )
336336
337+ async def _send_interaction_check_failure (
338+ self , interaction : discord .Interaction , message : str
339+ ):
340+ """Handles responding to interaction check failures.
341+ Mainly used for when an interaction is an autocomplete and
342+ providing the message in the autocomplete response.
343+ """
344+ if interaction .type is discord .InteractionType .autocomplete :
345+ await interaction .response .autocomplete (
346+ [discord .app_commands .Choice (name = message [:80 ], value = "None" )]
347+ )
348+ return
349+ await interaction .response .send_message (message , ephemeral = True )
350+
337351 async def interaction_check (self , interaction : discord .Interaction ):
338352 """Global checks for app commands."""
339353 if interaction .user .bot :
340354 return False
341355
342356 if interaction .guild :
343357 if not (await self .client .ignored_channel_or_guild (interaction )):
344- await interaction . response . send_message (
345- "This channel or server is ignored." , ephemeral = True
358+ await self . _send_interaction_check_failure (
359+ interaction , _ ( "This channel or server is ignored." )
346360 )
347361 return False
348362
349363 if not (await self .client .allowed_by_whitelist_blacklist (interaction .user )):
350- await interaction . response . send_message (
351- "You are not permitted to use commands because of an allowlist or blocklist." ,
352- ephemeral = True ,
364+ await self . _send_interaction_check_failure (
365+ interaction ,
366+ _ ( "You are not permitted to use commands because of an allowlist or blocklist." ) ,
353367 )
354368 return False
355369
0 commit comments