Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2714](https://github.com/Pycord-Development/pycord/pull/2714))
- Added the ability to pass a `datetime.time` object to `format_dt`.
([#2747](https://github.com/Pycord-Development/pycord/pull/2747))
- Added conversion to `Member` in `MentionableConverter`.
([#2775](https://github.com/Pycord-Development/pycord/pull/2775))
- Added `discord.Interaction.created_at`.
([#2801](https://github.com/Pycord-Development/pycord/pull/2801))

Expand Down
30 changes: 24 additions & 6 deletions discord/ext/bridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Converter,
Group,
GuildChannelConverter,
MemberConverter,
RoleConverter,
UserConverter,
)
Expand Down Expand Up @@ -566,13 +567,21 @@ def predicate(func: Callable | ApplicationCommand):


class MentionableConverter(Converter):
"""A converter that can convert a mention to a user or a role."""
"""A converter that can convert a mention to a member, a user or a role."""

async def convert(self, ctx, argument):
try:
return await RoleConverter().convert(ctx, argument)
except BadArgument:
return await UserConverter().convert(ctx, argument)
pass

if ctx.guild:
try:
return await MemberConverter().convert(ctx, argument)
except BadArgument:
pass

return await UserConverter().convert(ctx, argument)


class AttachmentConverter(Converter):
Expand Down Expand Up @@ -600,6 +609,7 @@ async def convert(self, ctx, arg: bool):
SlashCommandOptionType.mentionable: MentionableConverter,
SlashCommandOptionType.number: float,
SlashCommandOptionType.attachment: AttachmentConverter,
discord.Member: MemberConverter,
}


Expand All @@ -608,16 +618,24 @@ class BridgeOption(Option, Converter):
command option and a prefixed command argument for bridge commands.
"""

def __init__(self, input_type, *args, **kwargs):
self.converter = kwargs.pop("converter", None)
super().__init__(input_type, *args, **kwargs)

self.converter = self.converter or BRIDGE_CONVERTER_MAPPING.get(input_type)

async def convert(self, ctx, argument: str) -> Any:
try:
if self.converter is not None:
converted = await self.converter.convert(ctx, argument)
converted = await self.converter().convert(ctx, argument)
else:
converter = BRIDGE_CONVERTER_MAPPING[self.input_type]
if issubclass(converter, Converter):
converter = BRIDGE_CONVERTER_MAPPING.get(self.input_type)
if isinstance(converter, type) and issubclass(converter, Converter):
converted = await converter().convert(ctx, argument) # type: ignore # protocol class
else:
elif callable(converter):
converted = converter(argument)
else:
raise TypeError(f"Invalid converter: {converter}")

if self.choices:
choices_names: list[str | int | float] = [
Expand Down
Loading