Python discord.ext.commands.MemberConverter() Examples

The following are 4 code examples of discord.ext.commands.MemberConverter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module discord.ext.commands , or try the search function .
Example #1
Source File: functions.py    From nano-chan with MIT License 5 votes vote down vote up
def convert(self, ctx, argument):
        """Discord converter."""
        try:
            argument = extract_id(argument)
            m = await commands.MemberConverter().convert(ctx, argument)
        except commands.BadArgument:
            try:
                return str(int(argument, base=10))
            except ValueError:
                raise commands.BadArgument(f"{argument} is not a valid'\
                                            'member or member ID.") from None
        else:
            can_execute = ctx.author.id == ctx.bot.owner_id or \
                ctx.author == ctx.guild.owner or \
                ctx.author.top_role > m.top_role

            if not can_execute:
                raise commands.BadArgument('You cannot do this action on this'
                                           ' user due to role hierarchy.')
            return m 
Example #2
Source File: karma.py    From rubbergod with GNU General Public License v3.0 4 votes vote down vote up
def stalk(self, ctx, *args):
        try:
            converter = commands.MemberConverter()
            target_member = await converter.convert(ctx=ctx, argument=' '.join(args))
        except commands.errors.BadArgument:
            await ctx.send(utils.fill_message('member_not_found', user=ctx.author.id))
            return

        await ctx.send(self.karma.karma_get(ctx.author, target_member))
        await self.check.botroom_check(ctx.message) 
Example #3
Source File: rushwars.py    From SML-Cogs with MIT License 4 votes vote down vote up
def rw_player(self, ctx, player=None):
        """Player profile.

        player can be a player tag or a Discord member.
        """
        server = ctx.message.server
        author = ctx.message.author
        member = None
        tag = None

        if player is None:
            tag = self.settings.get(server.id, {}).get(author.id)
        else:
            try:
                cvt = MemberConverter(ctx, player)
                member = cvt.convert()
            except BadArgument:
                # cannot convert to member. Assume argument is a tag
                tag = clean_tag(player)
            else:
                tag = self.settings.get(server.id, {}).get(member.id)

        if tag is None:
            await self.bot.say("Can’t find tag associated with user.")
            return

        try:
            p = await self.api.fetch_player(tag)
        except RushWarsAPIError as e:
            await self.bot.say("RushWarsAPIError")
        else:
            await self.bot.say(embed=RWEmbed.player(p)) 
Example #4
Source File: commandargs.py    From MangoByte with MIT License 3 votes vote down vote up
def convert(cls, ctx, player):
		is_author = player is None
		if is_author:
			player = ctx.message.author

		try:
			player = int(player)
		except (ValueError, TypeError):
			pass # This either this is a discord user or an invalid argument

		if isinstance(player, int):
			if player > 76561197960265728:
				player -= 76561197960265728
			# Don't have to rate limit here because this will be first query ran
			player_info = await httpgetter.get(f"https://api.opendota.com/api/players/{player}", cache=False, errors=opendota_html_errors)

			if player_info.get("profile") is None:
				raise CustomBadArgument(NoMatchHistoryError(player))
			return cls(player, f"[{player_info['profile']['personaname']}](https://www.opendota.com/players/{player})", is_author)

		if not isinstance(player, discord.User):
			try:
				player = await commands.MemberConverter().convert(ctx, str(player))
			except commands.BadArgument:
				raise CustomBadArgument(UserError("Ya gotta @mention a user who has been linked to a steam id, or just give me a their steam id"))

		userinfo = botdata.userinfo(player.id)
		if userinfo.steam is None:
			if is_author:
				raise CustomBadArgument(SteamNotLinkedError())
			else:
				raise CustomBadArgument(SteamNotLinkedError(player))
		return cls(userinfo.steam, player.mention, is_author)