Python discord.ext.commands 模块,RoleConverter() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用discord.ext.commands.RoleConverter()

项目:Excalibot    作者:endreman0    | 项目源码 | 文件源码
def find_target(self, ctx, arg):
        """Returns the ID of the given target"""
        if arg.casefold() in ('everyone', 'all'):
            return discord.Object(id=0)

        try:
            return await MemberConverter().convert(ctx, arg)
        except BadArgument:
            pass

        try:
            return await RoleConverter().convert(ctx, arg)
        except BadArgument:
            pass

        return None
项目:MangoByte    作者:mdiller    | 项目源码 | 文件源码
def config_set_parse(self, ctx, var, value):
        if value in [ "default", "reset", "clear", "none", "null" ]:
            return var["default"]

        if var["type"] == bool:
            if value.lower() in [ "enable", "enabled", "true", "yes" ]:
                return True
            elif value.lower() in [ "disable", "disabled", "false", "no" ]:
                return False
            else:
                raise UserError("Invalid input. Give me something like `enable` or `disable`")
        elif var["type"] == discord.TextChannel:
            try:
                channel = await commands.TextChannelConverter().convert(ctx, value)
                return channel.id
            except commands.BadArgument:
                raise UserError("Invalid input. Give me a channel reference like `#general`")
        elif var["type"] == discord.Role:
            try:
                channel = await commands.RoleConverter().convert(ctx, value)
                return channel.id
            except commands.BadArgument:
                raise UserError("Invalid input. Give me a role reference like `@BotAdmin`")
        elif var["type"] == "GttsLang":
            lang = GttsLang.get(value)
            if lang is None:
                raise UserError("Invalid input. See https://github.com/mdiller/MangoByte/blob/master/resource/json/gtts_languages.json for valid langs")
            else:
                return lang.lang
        else:
            raise ValueError("I don't know how to parse this type")
        embed.add_field(name="Example", value=f"`?config {var['key']} {var['example']}`")
        return embed