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

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

项目:aryas    作者:lattkkthxbbye    | 项目源码 | 文件源码
def _add_entries(self, commands):
        """
        Adds commands from a dict to the paginator
        :param commands: the dict with commands
        """
        for name, command in commands:
            # skip aliases
            if name in command.aliases:
                continue

            if isinstance(command, Group):
                self._expand_group(command, '')
                continue

            entry = '**{0}** - {1}'.format(name, command.short_doc)
            shortened = self.shorten(entry)
            self._paginator.add_line(shortened)
项目:aryas    作者:lattkkthxbbye    | 项目源码 | 文件源码
def _expand_group(self, group, prefix):
        """
        Recursively expands a Group into paginator
        :param group: the Group to expand
        :param prefix: prefix of the line
        """
        if not isinstance(group, Group):
            entry = '**{prefix}{0}** - {1}'.format(group.name, group.short_doc, prefix=prefix)
            shortened = self.shorten(entry)
            self._paginator.add_line(shortened)
        else:
            entry = '**{prefix}{0}** - {1}'.format(group.name, group.short_doc, prefix=prefix)
            shortened = self.shorten(entry)
            self._paginator.add_line(shortened)
            for subcommand in group.commands.copy().values():
                # Build the prefix with group name so we get a nice list
                self._expand_group(subcommand, '    {prefix}{0} '.format(group.name, prefix=prefix))
项目:Nurevam    作者:Maverun    | 项目源码 | 文件源码
def _add_subcommands_to_page(self, max_width, commands):
        for name, command in commands:
            if name in command.aliases:
                # skip aliases
                continue

            entry = '  {0:<{width}} {1}'.format(name, command.short_doc, width=max_width)
            shortened = self.shorten(entry)
            self._paginator.add_line(shortened)
            if isinstance(command,Group):
                    max_count = len(command.commands)
                    uni = "?"
                    for index,command in enumerate(command.commands,start = 1):
                        if index == max_count: uni = "?"
                        entry = '   {uni}{0:<{width}} {1}'.format(command.name, command.short_doc, width=max_width,uni=uni)
                        shortened = self.shorten(entry)
                        self._paginator.add_line(shortened)
项目:Harmonbot    作者:Harmon758    | 项目源码 | 文件源码
def group(name=None, **attrs):
    return commands.command(name=name, cls=Group, **attrs)
项目:aikaterna-cogs    作者:aikaterna    | 项目源码 | 文件源码
def imgwelcome_bonus(self, ctx):
        """Toggle display of additional text welcome messages when a user joins the server."""
        if ctx.invoked_subcommand is None or isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:aikaterna-cogs    作者:aikaterna    | 项目源码 | 文件源码
def imgwelcome_font(self, ctx):
        """Place your font files in the data/imgwelcome/fonts/ directory.
        Valid font areas to change are: welcome, server and name.
        """
        if ctx.invoked_subcommand is None or isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:HAHA-NO-UR    作者:DamourYouKnow    | 项目源码 | 文件源码
def get_help(bot) -> tuple:
    """
    Return a general Embed onject for help.
    :param bot: the Yasen instance.
    :return: a discord Embed object for general help.
    """
    from bot import __title__ as name
    prefix = bot.prefix
    description = f'For detailed help please use {prefix}help [command_name]'
    embed = Embed(colour=bot.colour, description=description)
    embed.set_author(name=f'{name} Help', icon_url=bot.user.avatar_url)
    cog_cmd = {}
    all_help = {}
    for command in bot.commands.values():
        _name = command.name
        for n in __resolve_alias(command):
            all_help[n] = single_help(bot, command, _name)
        cog_name = ' '.join(split_camel(command.cog_name) + ['Commands'])
        if cog_name not in cog_cmd:
            cog_cmd[cog_name] = []
        cog_cmd[cog_name].append(f'`{_name}`')
        if isinstance(command, Group):
            for sub in command.commands.values():
                _child_name = sub.name
                full_name = f'{_name} {_child_name}'
                all_help[full_name] = single_help(bot, sub, full_name)
                cog_cmd[cog_name].append(full_name)
    for key in sorted(cog_cmd.keys()):
        embed.add_field(
            name=key, value=', '.join(set(cog_cmd[key])), inline=False
        )
    return embed, all_help
项目:Squid-Plugins    作者:tekulvw    | 项目源码 | 文件源码
def channel(self, ctx):
        """Channel based permissions

        Will be overridden by role based permissions."""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:Squid-Plugins    作者:tekulvw    | 项目源码 | 文件源码
def role(self, ctx):
        """Role based permissions

        Overrides channel based permissions"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:goldmine    作者:Armored-Dragon    | 项目源码 | 文件源码
def repo(self, ctx):
        """Repo management commands"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await self.bot.send_cmd_help(ctx)
            return
项目:ax-cogs    作者:Aioxas    | 项目源码 | 文件源码
def member(self, ctx):
        """Member settings"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:ax-cogs    作者:Aioxas    | 项目源码 | 文件源码
def keeper(self, ctx):
        """bookkeeper settings"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:Shallus-Bot    作者:cgropp    | 项目源码 | 文件源码
def repo(self, ctx):
        """Repo management commands"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Maybe-Useful-Cogs    作者:AznStevy    | 项目源码 | 文件源码
def profileset(self, ctx):
        """Profile options"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Maybe-Useful-Cogs    作者:AznStevy    | 项目源码 | 文件源码
def rankset(self, ctx):
        """Rank options"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Maybe-Useful-Cogs    作者:AznStevy    | 项目源码 | 文件源码
def levelupset(self, ctx):
        """Level-Up options"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Maybe-Useful-Cogs    作者:AznStevy    | 项目源码 | 文件源码
def lvladminbg(self, ctx):
        """Admin Background Configuration"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Dumb-Cogs    作者:irdumbs    | 项目源码 | 文件源码
def welcomeset_msg(self, ctx):
        """Manage welcome messages
        """
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Dumb-Cogs    作者:irdumbs    | 项目源码 | 文件源码
def welcomeset_bot(self, ctx):
        """Special welcome for bots"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:Dumb-Cogs    作者:irdumbs    | 项目源码 | 文件源码
def replset_print(self, ctx):
        """Sets where repl content goes when response is too large."""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:Dumb-Cogs    作者:irdumbs    | 项目源码 | 文件源码
def team_list(self, ctx):
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
项目:KeekoBot    作者:DavidNeon    | 项目源码 | 文件源码
def welcomeset_msg(self, ctx):
        """Manage welcome messages
        """
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:KeekoBot    作者:DavidNeon    | 项目源码 | 文件源码
def welcomeset_bot(self, ctx):
        """Special welcome for bots"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:KeekoBot    作者:DavidNeon    | 项目源码 | 文件源码
def repo(self, ctx):
        """Repo management commands"""
        if ctx.invoked_subcommand is None or \
                isinstance(ctx.invoked_subcommand, commands.Group):
            await send_cmd_help(ctx)
            return
项目:ORELS-Cogs    作者:orels1    | 项目源码 | 文件源码
def _set(self, ctx):
        """Configure build command"""

        if ctx.invoked_subcommand is None or isinstance(ctx.invoked_subcommand, commands.Group):
            await self.bot.say("Type help build set for info.")
项目:aryas    作者:lattkkthxbbye    | 项目源码 | 文件源码
def format(self):
        """
        Formats the help page.
        """
        # Adapted from discord.ext.commands.formatter.HelpFormatter.format

        self._paginator = AryasPaginator()

        description = self.command.description if not self.is_cog() else inspect.getdoc(self.command)

        if description:
            self._paginator.new_page(description=description)

        if isinstance(self.command, Command):
            # long help doc
            if self.command.help:
                self._paginator.add_line(self.command.help)

            self._paginator.set_name(self.get_command_signature())
            self._paginator.make_field(inline=False)

            # if it's just a single command we're done here
            if not self.has_subcommands():
                return self._paginator.pages

        # Helper method for sorting by category (cog)
        def category(tup):
            cog = tup[1].cog_name
            # Unicode invisible space is there to set No Category last
            return cog + ':' if cog is not None else '\u200bNo Category:'

        # if command is a bot we need to process the entire command list
        if self.is_bot():
            data = sorted(self.filter_command_list(), key=category)
            for category, commands in itertools.groupby(data, key=category):
                commands = list(commands)
                if len(commands) > 0:
                    self._add_entries(commands)
                    self._paginator.set_name(category)
                    self._paginator.make_field(inline=False)
        else:
            # if command is just a cog or Group we can print all the commands
            # returned by filter_command_list
            self._add_entries(self.filter_command_list())
            self._paginator.set_name('Commands:')
            self._paginator.make_field(inline=False)

        # Get the ending message
        self._paginator.set_name('More:')
        self._paginator.add_line(self.get_ending_note())
        self._paginator.make_field(inline=False)
        return self._paginator.pages
项目:StreamNotificationBot    作者:ivandardi    | 项目源码 | 文件源码
def _make_commands(self):
        group = commands.Group(
            name=self.service_name,
            callback=self._group_command,
            help=self._make_help_string(strings.group_command_help),
        )
        group.instance = self
        cmd = commands.Command(
            name='add',
            aliases=['subscribe'],
            callback=self._add_command,
            help=self._make_help_string(strings.add_command_help),
        )
        cmd.instance = self
        group.add_command(cmd)
        cmd = commands.Command(
            name='del',
            aliases=['unsubscribe', 'remove', 'delete'],
            callback=self._del_command,
            help=self._make_help_string(strings.del_command_help),
        )
        cmd.instance = self
        group.add_command(cmd)
        cmd = commands.Command(
            name='list',
            callback=self._list_command,
            help=self._make_help_string(strings.list_command_help),
        )
        cmd.instance = self
        group.add_command(cmd)
        cmd = commands.Command(
            name='enable',
            callback=self._enable_command,
            help=self._make_help_string(strings.enable_command_help),
        )
        cmd.instance = self
        group.add_command(cmd)
        cmd = commands.Command(
            name='disable',
            callback=self._disable_command,
            help=self._make_help_string(strings.disable_command_help),
        )
        cmd.instance = self
        group.add_command(cmd)

        return group