async def convert(cls, ctx: commands.Context, value: str) -> int: """ Converts the given value to a valid user ID. """ match = commands.IDConverter()._get_id_match(value) or re.match(r'<@!?([0-9]+)>$', value) if match is not None: return int(match.group(1)) raise commands.UserNotFound(value)
async def convert(self, ctx: commands.Context, argument: str) -> discord.User: """Converter method""" match = self._get_id_match(argument) or re.match( r'<@!?([0-9]{15,20})>$', argument) if match is not None: user_id = int(match.group(1)) result = ctx.bot.get_user(user_id) or discord.utils.get( ctx.message.mentions, id=user_id) if result is None: try: result = await ctx.bot.fetch_user(user_id) except discord.HTTPException: raise commands.UserNotFound(argument) from None return result raise commands.UserNotFound(argument)
async def convert(self, ctx, arg): try: return await commands.UserConverter().convert(ctx, arg) except commands.UserNotFound: pass try: return await ctx.bot.fetch_user(int(arg)) except (discord.NotFound, discord.HTTPException, ValueError): raise commands.UserNotFound(arg)
async def convert(self, ctx: context.Context, argument: str) -> discord.User: user = None try: user = await super().convert(ctx, argument) except commands.BadArgument: pass if not user: try: user = await ctx.bot.fetch_user(argument) except (discord.NotFound, discord.HTTPException): raise commands.UserNotFound(argument=argument) return user
async def convert(self, ctx, argument): try: return await commands.MemberConverter().convert(ctx, argument) except commands.MemberNotFound: pass try: return await commands.UserConverter().convert(ctx, argument) except commands.UserNotFound: pass #use the armigers db as a basis for partial matching, #since discord.py only does whole matches (and it would be too #inefficient to redo its behaviour with that) query = await ctx.bot.dbc.execute_fetchone( "SELECT * FROM armigers_e WHERE qualified_name LIKE ? AND discord_id IS NOT NULL", (f"%{argument}%", )) if query: user = await utils.get_user(ctx.bot, query[1]) if user: return user raise commands.UserNotFound(argument)