async def filter_commands(self, commands, *, sort=False, key=None):
if sort and key is None:<EOL><INDENT>key = lambda c: c.name<EOL><DEDENT>iterator = commands if self.show_hidden else filter(lambda c: not c.hidden, commands)<EOL>if not self.verify_checks:<EOL><INDENT>return sorted(iterator, key=key) if sort else list(iterator)<EOL><DEDENT>async def predicate(cmd):<EOL><INDENT>try:<EOL><INDENT>return await cmd.can_run(self.context)<EOL><DEDENT>except CommandError:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>ret = []<EOL>for cmd in iterator:<EOL><INDENT>valid = await predicate(cmd)<EOL>if valid:<EOL><INDENT>ret.append(cmd)<EOL><DEDENT><DEDENT>if sort:<EOL><INDENT>ret.sort(key=key)<EOL><DEDENT>return ret<EOL>
|coro|

        Returns a filtered list of commands and optionally sorts them.

        This takes into account the :attr:`verify_checks` and :attr:`show_hidden`
        attributes.

        Parameters
        ------------
        commands: Iterable[:class:`Command`]
            An iterable of commands that are getting filtered.
        sort: :class:`bool`
            Whether to sort the result.
        key: Optional[Callable[:class:`Command`, Any]]
            An optional key function to pass to :func:`py:sorted` that
            takes a :class:`Command` as its sole parameter. If ``sort`` is
            passed as ``True`` then this will default as the command name.

        Returns
        ---------
        List[:class:`Command`]
            A list of commands that passed the filter.