51
51
Converter ,
52
52
Group ,
53
53
GuildChannelConverter ,
54
+ MemberConverter ,
54
55
RoleConverter ,
55
56
UserConverter ,
56
57
)
@@ -553,13 +554,21 @@ def predicate(func: Callable | ApplicationCommand):
553
554
554
555
555
556
class MentionableConverter (Converter ):
556
- """A converter that can convert a mention to a user or a role."""
557
+ """A converter that can convert a mention to a member, a user or a role."""
557
558
558
559
async def convert (self , ctx , argument ):
559
560
try :
560
561
return await RoleConverter ().convert (ctx , argument )
561
562
except BadArgument :
562
- return await UserConverter ().convert (ctx , argument )
563
+ pass
564
+
565
+ if ctx .guild :
566
+ try :
567
+ return await MemberConverter ().convert (ctx , argument )
568
+ except BadArgument :
569
+ pass
570
+
571
+ return await UserConverter ().convert (ctx , argument )
563
572
564
573
565
574
class AttachmentConverter (Converter ):
@@ -587,6 +596,7 @@ async def convert(self, ctx, arg: bool):
587
596
SlashCommandOptionType .mentionable : MentionableConverter ,
588
597
SlashCommandOptionType .number : float ,
589
598
SlashCommandOptionType .attachment : AttachmentConverter ,
599
+ discord .Member : MemberConverter ,
590
600
}
591
601
592
602
@@ -595,16 +605,24 @@ class BridgeOption(Option, Converter):
595
605
command option and a prefixed command argument for bridge commands.
596
606
"""
597
607
608
+ def __init__ (self , input_type , * args , ** kwargs ):
609
+ self .converter = kwargs .pop ("converter" , None )
610
+ super ().__init__ (input_type , * args , ** kwargs )
611
+
612
+ self .converter = self .converter or BRIDGE_CONVERTER_MAPPING .get (input_type )
613
+
598
614
async def convert (self , ctx , argument : str ) -> Any :
599
615
try :
600
616
if self .converter is not None :
601
- converted = await self .converter .convert (ctx , argument )
617
+ converted = await self .converter () .convert (ctx , argument )
602
618
else :
603
- converter = BRIDGE_CONVERTER_MAPPING [ self .input_type ]
604
- if issubclass (converter , Converter ):
619
+ converter = BRIDGE_CONVERTER_MAPPING . get ( self .input_type )
620
+ if isinstance ( converter , type ) and issubclass (converter , Converter ):
605
621
converted = await converter ().convert (ctx , argument ) # type: ignore # protocol class
606
- else :
622
+ elif callable ( converter ) :
607
623
converted = converter (argument )
624
+ else :
625
+ raise TypeError (f"Invalid converter: { converter } " )
608
626
609
627
if self .choices :
610
628
choices_names : list [str | int | float ] = [choice .name for choice in self .choices ]
0 commit comments