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


Python commands.CheckFailure方法代码示例

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


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

示例1: cooldown_check

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def cooldown_check():
    """Command check to ensure the user only calls specific commands every 12 hours.
    """
    async def pred(ctx):
        if not ctx.db_stats.last_used:
            await ctx.db_stats.update_last_used()
            return True

        if ctx.db_stats.ignore_cooldowns:
            return True

        delta = datetime.now() - ctx.db_stats.last_used
        if delta.total_seconds() < 43200:  # 12 hours
            raise commands.CheckFailure(f'You\'re on cooldown! Please wait another '
                                        f'{readable_time(43200 - delta.total_seconds())}.')
        await ctx.db_stats.update_last_used()
        ctx.db_stats = ctx.db_stats
        return True
    return commands.check(pred) 
开发者ID:python-discord,项目名称:code-jam-5,代码行数:21,代码来源:farmer_game.py

示例2: on_command_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def on_command_error(self, error, ctx):
        ignored = (commands.NoPrivateMessage, commands.DisabledCommand, commands.CheckFailure,
                   commands.CommandNotFound, commands.UserInputError, discord.HTTPException)
        error = getattr(error, 'original', error)

        if isinstance(error, ignored):
            return

        if ctx.message.server:
            fmt = 'Channel: {0} (ID: {0.id})\nGuild: {1} (ID: {1.id})'
        else:
            fmt = 'Channel: {0} (ID: {0.id})'

        exc = traceback.format_exception(type(error), error, error.__traceback__, chain=False)
        description = '```py\n%s\n```' % ''.join(exc)
        time = datetime.datetime.utcnow()

        name = ctx.command.qualified_name
        author = '{0} (ID: {0.id})'.format(ctx.message.author)
        location = fmt.format(ctx.message.channel, ctx.message.server)

        message = '{0} at {1}: Called by: {2} in {3}. More info: {4}'.format(name, time, author, location, description)

        self.bot.logs['discord'].critical(message) 
开发者ID:rauenzi,项目名称:discordbot.py,代码行数:26,代码来源:meta.py

示例3: load_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def load_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send("{} is not in the sudoers file. This incident will be reported.".format(ctx.author.display_name)) 
开发者ID:XNBlank,项目名称:sudoBot,代码行数:5,代码来源:admin.py

示例4: reload_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def reload_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send("{} is not in the sudoers file. This incident will be reported.".format(ctx.author.display_name)) 
开发者ID:XNBlank,项目名称:sudoBot,代码行数:5,代码来源:admin.py

示例5: reloadconf_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def reloadconf_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send("{} is not in the sudoers file. This incident will be reported.".format(ctx.author.display_name)) 
开发者ID:XNBlank,项目名称:sudoBot,代码行数:5,代码来源:admin.py

示例6: unload_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def unload_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send("{} is not in the sudoers file. This incident will be reported.".format(ctx.author.display_name)) 
开发者ID:XNBlank,项目名称:sudoBot,代码行数:5,代码来源:admin.py

示例7: is_owner

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def is_owner():
    def predicate(ctx):
        if author_is_owner(ctx):
            return True
        raise commands.CheckFailure("Only the bot owner may run this command.")

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:9,代码来源:checks.py

示例8: role_or_permissions

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def role_or_permissions(role_name, **perms):
    def predicate(ctx):
        if _role_or_permissions(ctx, lambda r: r.name.lower() == role_name.lower(), **perms):
            return True
        raise commands.CheckFailure(
            f"You require a role named {role_name} or these permissions to run this command: {', '.join(perms)}")

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:10,代码来源:checks.py

示例9: admin_or_permissions

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def admin_or_permissions(**perms):
    def predicate(ctx):
        admin_role = "Bot Admin"
        if _role_or_permissions(ctx, lambda r: r.name.lower() == admin_role.lower(), **perms):
            return True
        raise commands.CheckFailure(
            f"You require a role named Bot Admin or these permissions to run this command: {', '.join(perms)}")

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:11,代码来源:checks.py

示例10: can_edit_serverbrew

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def can_edit_serverbrew():
    def predicate(ctx):
        if ctx.author.guild_permissions.manage_guild or \
                any(r.name.lower() in BREWER_ROLES for r in ctx.author.roles) or \
                author_is_owner(ctx):
            return True
        raise commands.CheckFailure(
            "You do not have permission to manage server homebrew. Either __Manage Server__ "
            "Discord permissions or a role named \"Server Brewer\" or \"Dragonspeaker\" "
            "is required."
        )

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:15,代码来源:checks.py

示例11: feature_flag

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def feature_flag(flag_name, use_ddb_user=False, default=False):
    async def predicate(ctx):
        if use_ddb_user:
            ddb_user = await ctx.bot.ddb.get_ddb_user(ctx, ctx.author.id)
            if ddb_user is None:
                user = {"key": str(ctx.author.id), "anonymous": True}
            else:
                user = ddb_user.to_ld_dict()
        else:
            user = {"key": str(ctx.author.id), "name": str(ctx.author)}

        flag_on = await ctx.bot.ldclient.variation(flag_name, user, default)
        if flag_on:
            return True

        raise commands.CheckFailure(
            "This command is currently disabled. Check back later!"
        )

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:22,代码来源:checks.py

示例12: on_command_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def on_command_error(self, ctx, error):
        """Command error handler"""
        manager = MessageManager(ctx)

        if isinstance(error, commands.CommandNotFound):
            pass

        elif isinstance(error, commands.MissingRequiredArgument):
            pass

        elif isinstance(error, commands.NotOwner):
            pass

        elif isinstance(error, commands.NoPrivateMessage):
            await manager.send_message("You can't use that command in a private message")

        elif isinstance(error, commands.CheckFailure):
            await manager.send_message("You don't have the required permissions to do that")

        elif isinstance(error, commands.CommandOnCooldown):
            await manager.send_message(error)

        # Non Discord.py errors
        elif isinstance(error, commands.CommandInvokeError):
            if isinstance(error.original, discord.errors.Forbidden):
                pass
            elif isinstance(error.original, asyncio.TimeoutError):
                await manager.send_private_message("I'm not sure where you went. We can try this again later.")
            else:
                raise error

        else:
            raise error

        await manager.clean_messages() 
开发者ID:jgayfer,项目名称:spirit,代码行数:37,代码来源:core.py

示例13: on_command_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def on_command_error(self, context, exception):
        if isinstance(exception, commands.BadUnionArgument):
            msg = "Could not find the specified " + human_join(
                [c.__name__ for c in exception.converters]
            )
            await context.trigger_typing()
            await context.send(embed=discord.Embed(color=self.error_color, description=msg))

        elif isinstance(exception, commands.BadArgument):
            await context.trigger_typing()
            await context.send(
                embed=discord.Embed(color=self.error_color, description=str(exception))
            )
        elif isinstance(exception, commands.CommandNotFound):
            logger.warning("CommandNotFound: %s", exception)
        elif isinstance(exception, commands.MissingRequiredArgument):
            await context.send_help(context.command)
        elif isinstance(exception, commands.CheckFailure):
            for check in context.command.checks:
                if not await check(context):
                    if hasattr(check, "fail_msg"):
                        await context.send(
                            embed=discord.Embed(color=self.error_color, description=check.fail_msg)
                        )
                    if hasattr(check, "permission_level"):
                        corrected_permission_level = self.command_perm(
                            context.command.qualified_name
                        )
                        logger.warning(
                            "User %s does not have permission to use this command: `%s` (%s).",
                            context.author.name,
                            context.command.qualified_name,
                            corrected_permission_level.name,
                        )
            logger.warning("CheckFailure: %s", exception)
        else:
            logger.error("Unexpected exception:", exc_info=exception) 
开发者ID:kyb3r,项目名称:modmail,代码行数:39,代码来源:bot.py

示例14: fitwide_checks_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def fitwide_checks_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send('Nothing to see here comrade. ' +
                           '<:KKomrade:484470873001164817>') 
开发者ID:Toaster192,项目名称:rubbergod,代码行数:6,代码来源:fitwide.py

示例15: karma_error

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import CheckFailure [as 别名]
def karma_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            await ctx.send(utils.fill_message("insufficient_rights", user=ctx.author.id)) 
开发者ID:Toaster192,项目名称:rubbergod,代码行数:5,代码来源:karma.py


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