当前位置: 首页>>代码示例>>Python>>正文


Python commands.Cog方法代码示例

本文整理汇总了Python中discord.ext.commands.Cog方法的典型用法代码示例。如果您正苦于以下问题:Python commands.Cog方法的具体用法?Python commands.Cog怎么用?Python commands.Cog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord.ext.commands的用法示例。


在下文中一共展示了commands.Cog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: command_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def command_error(self, ctx: Context, error: CommandError) -> None:
        """Local error handler for the Snake Cog."""
        embed = Embed()
        embed.colour = Colour.red()

        if isinstance(error, BadArgument):
            embed.description = str(error)
            embed.title = random.choice(ERROR_REPLIES)

        elif isinstance(error, OSError):
            log.error(f"snake_card encountered an OSError: {error} ({error.original})")
            embed.description = "Could not generate the snake card! Please try again."
            embed.title = random.choice(ERROR_REPLIES)

        else:
            log.error(f"Unhandled tag command error: {error} ({error.original})")
            return

        await ctx.send(embed=embed)
    # endregion 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:22,代码来源:snakes_cog.py

示例2: walk_commands

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def walk_commands(cog: commands.Cog) -> t.Iterator[commands.Command]:
        """An iterator that recursively walks through `cog`'s commands and subcommands."""
        # Can't use Bot.walk_commands() or Cog.get_commands() cause those are instance methods.
        for command in cog.__cog_commands__:
            if command.parent is None:
                yield command
                if isinstance(command, commands.GroupMixin):
                    # Annoyingly it returns duplicates for each alias so use a set to fix that
                    yield from set(command.walk_commands()) 
开发者ID:python-discord,项目名称:bot,代码行数:11,代码来源:test_cogs.py

示例3: walk_cogs

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def walk_cogs(module: ModuleType) -> t.Iterator[commands.Cog]:
        """Yield all cogs defined in an extension."""
        for obj in module.__dict__.values():
            # Check if it's a class type cause otherwise issubclass() may raise a TypeError.
            is_cog = isinstance(obj, type) and issubclass(obj, commands.Cog)
            if is_cog and obj.__module__ == module.__name__:
                yield obj 
开发者ID:python-discord,项目名称:bot,代码行数:9,代码来源:test_cogs.py

示例4: cog_unload

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def cog_unload(self) -> None:
        """Cancel the init task and scheduled tasks when the cog unloads."""
        log.trace("Cog unload: cancelling the init_cog task")
        self.init_task.cancel()

        log.trace("Cog unload: cancelling the channel queue tasks")
        for task in self.queue_tasks:
            task.cancel()

        self.cancel_all() 
开发者ID:python-discord,项目名称:bot,代码行数:12,代码来源:help_channels.py

示例5: init_cog

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def init_cog(self) -> None:
        """Initialise the help channel system."""
        log.trace("Waiting for the guild to be available before initialisation.")
        await self.bot.wait_until_guild_available()

        log.trace("Initialising the cog.")
        await self.init_categories()
        await self.check_cooldowns()

        self.channel_queue = self.create_channel_queue()
        self.name_queue = self.create_name_queue()

        log.trace("Moving or rescheduling in-use channels.")
        for channel in self.get_category_channels(self.in_use_category):
            await self.move_idle_channel(channel, has_task=False)

        # Prevent the command from being used until ready.
        # The ready event wasn't used because channels could change categories between the time
        # the command is invoked and the cog is ready (e.g. if move_idle_channel wasn't called yet).
        # This may confuse users. So would potentially long delays for the cog to become ready.
        self.close_command.enabled = True

        await self.init_available()

        log.info("Cog is ready!")
        self.ready.set()

        self.report_stats() 
开发者ID:python-discord,项目名称:bot,代码行数:30,代码来源:help_channels.py

示例6: get_all_help_choices

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def get_all_help_choices(self) -> set:
        """
        Get all the possible options for getting help in the bot.

        This will only display commands the author has permission to run.

        These include:
        - Category names
        - Cog names
        - Group command names (and aliases)
        - Command names (and aliases)
        - Subcommand names (with parent group and aliases for subcommand, but not including aliases for group)

        Options and choices are case sensitive.
        """
        # first get all commands including subcommands and full command name aliases
        choices = set()
        for command in await self.filter_commands(self.context.bot.walk_commands()):
            # the the command or group name
            choices.add(str(command))

            if isinstance(command, Command):
                # all aliases if it's just a command
                choices.update(command.aliases)
            else:
                # otherwise we need to add the parent name in
                choices.update(f"{command.full_parent_name} {alias}" for alias in command.aliases)

        # all cog names
        choices.update(self.context.bot.cogs)

        # all category names
        choices.update(cog.category for cog in self.context.bot.cogs.values() if hasattr(cog, "category"))
        return choices 
开发者ID:python-discord,项目名称:bot,代码行数:36,代码来源:help.py

示例7: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def setup(bot: Bot) -> None:
    """Load the Help cog."""
    bot.add_cog(Help(bot))
    log.info("Cog loaded: Help") 
开发者ID:python-discord,项目名称:bot,代码行数:6,代码来源:help.py

示例8: locked

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def locked() -> Callable:
    """
    Allows the user to only run one instance of the decorated command at a time.

    Subsequent calls to the command from the same author are ignored until the command has completed invocation.

    This decorator must go before (below) the `command` decorator.
    """
    def wrap(func: Callable) -> Callable:
        func.__locks = WeakValueDictionary()

        @wraps(func)
        async def inner(self: Cog, ctx: Context, *args, **kwargs) -> None:
            lock = func.__locks.setdefault(ctx.author.id, Lock())
            if lock.locked():
                embed = Embed()
                embed.colour = Colour.red()

                log.debug("User tried to invoke a locked command.")
                embed.description = (
                    "You're already using this command. Please wait until it is done before you use it again."
                )
                embed.title = random.choice(ERROR_REPLIES)
                await ctx.send(embed=embed)
                return

            async with func.__locks.setdefault(ctx.author.id, Lock()):
                await func(self, ctx, *args, **kwargs)
        return inner
    return wrap 
开发者ID:python-discord,项目名称:bot,代码行数:32,代码来源:decorators.py

示例9: add_cog

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def add_cog(self, cog: commands.Cog) -> None:
        """Adds a "cog" to the bot and logs the operation."""
        super().add_cog(cog)
        log.info(f"Cog loaded: {cog.qualified_name}") 
开发者ID:python-discord,项目名称:bot,代码行数:6,代码来源:bot.py

示例10: test_loads

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def test_loads(bot):
    assert bot.get_cog("Jishaku")
    assert isinstance(bot.get_cog("Jishaku"), commands.Cog)

    assert bot.get_command("jsk")
    assert isinstance(bot.get_command("jsk"), commands.Command) 
开发者ID:Gorialis,项目名称:jishaku,代码行数:8,代码来源:test_cog.py

示例11: add_cog

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def add_cog(self, cog: commands.Cog) -> None:
        """
        Delegate to super to register `cog`.

        This only serves to make the info log, so that extensions don't have to.
        """
        super().add_cog(cog)
        log.info(f"Cog loaded: {cog.qualified_name}") 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:10,代码来源:bot.py

示例12: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def setup(bot: SeasonalBot) -> None:
    """Cog loader for pride facts."""
    bot.add_cog(PrideFacts(bot)) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:5,代码来源:pride_facts.py

示例13: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def setup(bot: commands.Bot) -> None:
    """Cog loader for pride anthem."""
    bot.add_cog(PrideAnthem(bot)) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:5,代码来源:pride_anthem.py

示例14: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def setup(bot: commands.Bot) -> None:
    """Cog load."""
    bot.add_cog(PrideAvatar(bot)) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:5,代码来源:pride_avatar.py

示例15: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Cog [as 别名]
def setup(bot: commands.Bot) -> None:
    """Cog loader for drag queen name generator."""
    bot.add_cog(DragNames(bot)) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:5,代码来源:drag_queen_name.py


注:本文中的discord.ext.commands.Cog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。