當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。