diff options
Diffstat (limited to 'bot/converters.py')
| -rw-r--r-- | bot/converters.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/converters.py b/bot/converters.py index 898822165..7c62f92dd 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -330,6 +330,28 @@ def proxy_user(user_id: str) -> discord.Object: return user +class UserMentionOrID(UserConverter): + """ + Converts to a `discord.User`, but only if a mention or userID is provided. + + Unlike the default `UserConverter`, it does allow conversion from name, or name#descrim. + + This is useful in cases where that lookup strategy would lead to ambiguity. + """ + + async def convert(self, ctx: Context, argument: str) -> discord.User: + """Convert the `arg` to a `discord.User`.""" + print(argument) + match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument) + + print(match) + + if match is not None: + return await super().convert(ctx, argument) + else: + raise BadArgument(f"`{argument}` is not a User mention or a User ID.") + + class FetchedUser(UserConverter): """ Converts to a `discord.User` or, if it fails, a `discord.Object`. |