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

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

项目:Chiaki-Nanami    作者:Ikusaba-san    | 项目源码 | 文件源码
def ranged(low, high=None, *, type=int):
    'Converter to check if an argument is in a certain range INCLUSIVELY'
    if high is None:
        low, high = 0, low

    def ranged_argument(arg):
        result = type(arg)
        if low <= result <= high:
            return result
        raise commands.BadArgument(f'Value must be between {low} and {high}, '
                                   f'or equal to {low} or {high}.')
    return ranged_argument
项目:RPGBot    作者:henry232323    | 项目源码 | 文件源码
def union(*classes):
    class Union(commands.Converter):
        async def convert(self, ctx, argument):
            for cls in classes:
                try:
                    if cls in converters:
                        cls = converters[cls]
                    return await cls.convert(self, ctx, argument)
                except Exception as e:
                    pass
            else:
                raise e

    return Union
项目:PyMiki    作者:TheGrammarJew    | 项目源码 | 文件源码
def __init__(self, converter=None, *, default=None):
        if isinstance(converter, type) and issubclass(converter, commands.Converter):
            converter = converter()

        if converter is not None and not isinstance(converter, commands.Converter):
            raise TypeError('commands.Converter subclass necessary.')

        self.converter = converter
        self.default = default