51
51
Converter ,
52
52
Group ,
53
53
GuildChannelConverter ,
54
+ MemberConverter ,
54
55
RoleConverter ,
55
56
UserConverter ,
56
57
)
@@ -566,13 +567,21 @@ def predicate(func: Callable | ApplicationCommand):
566
567
567
568
568
569
class MentionableConverter (Converter ):
569
- """A converter that can convert a mention to a user or a role."""
570
+ """A converter that can convert a mention to a member, a user or a role."""
570
571
571
572
async def convert (self , ctx , argument ):
572
573
try :
573
574
return await RoleConverter ().convert (ctx , argument )
574
575
except BadArgument :
575
- return await UserConverter ().convert (ctx , argument )
576
+ pass
577
+
578
+ if ctx .guild :
579
+ try :
580
+ return await MemberConverter ().convert (ctx , argument )
581
+ except BadArgument :
582
+ pass
583
+
584
+ return await UserConverter ().convert (ctx , argument )
576
585
577
586
578
587
class AttachmentConverter (Converter ):
@@ -600,6 +609,7 @@ async def convert(self, ctx, arg: bool):
600
609
SlashCommandOptionType .mentionable : MentionableConverter ,
601
610
SlashCommandOptionType .number : float ,
602
611
SlashCommandOptionType .attachment : AttachmentConverter ,
612
+ discord .Member : MemberConverter ,
603
613
}
604
614
605
615
@@ -608,16 +618,24 @@ class BridgeOption(Option, Converter):
608
618
command option and a prefixed command argument for bridge commands.
609
619
"""
610
620
621
+ def __init__ (self , input_type , * args , ** kwargs ):
622
+ self .converter = kwargs .pop ("converter" , None )
623
+ super ().__init__ (input_type , * args , ** kwargs )
624
+
625
+ self .converter = self .converter or BRIDGE_CONVERTER_MAPPING .get (input_type )
626
+
611
627
async def convert (self , ctx , argument : str ) -> Any :
612
628
try :
613
629
if self .converter is not None :
614
- converted = await self .converter .convert (ctx , argument )
630
+ converted = await self .converter () .convert (ctx , argument )
615
631
else :
616
- converter = BRIDGE_CONVERTER_MAPPING [ self .input_type ]
617
- if issubclass (converter , Converter ):
632
+ converter = BRIDGE_CONVERTER_MAPPING . get ( self .input_type )
633
+ if isinstance ( converter , type ) and issubclass (converter , Converter ):
618
634
converted = await converter ().convert (ctx , argument ) # type: ignore # protocol class
619
- else :
635
+ elif callable ( converter ) :
620
636
converted = converter (argument )
637
+ else :
638
+ raise TypeError (f"Invalid converter: { converter } " )
621
639
622
640
if self .choices :
623
641
choices_names : list [str | int | float ] = [
0 commit comments