本文整理汇总了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
示例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)
示例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)
示例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))