當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。