当前位置: 首页>>代码示例>>Python>>正文


Python commands.MemberConverter方法代码示例

本文整理汇总了Python中discord.ext.commands.MemberConverter方法的典型用法代码示例。如果您正苦于以下问题:Python commands.MemberConverter方法的具体用法?Python commands.MemberConverter怎么用?Python commands.MemberConverter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord.ext.commands的用法示例。


在下文中一共展示了commands.MemberConverter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import MemberConverter [as 别名]
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 
开发者ID:dashwav,项目名称:nano-chan,代码行数:22,代码来源:functions.py

示例2: convert

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import MemberConverter [as 别名]
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) 
开发者ID:mdiller,项目名称:MangoByte,代码行数:35,代码来源:commandargs.py

示例3: stalk

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import MemberConverter [as 别名]
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) 
开发者ID:Toaster192,项目名称:rubbergod,代码行数:12,代码来源:karma.py

示例4: rw_player

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import MemberConverter [as 别名]
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)) 
开发者ID:smlbiobot,项目名称:SML-Cogs,代码行数:34,代码来源:rushwars.py


注:本文中的discord.ext.commands.MemberConverter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。