Python discord.ext.commands.CheckFailure() Examples
The following are 30
code examples of discord.ext.commands.CheckFailure().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
discord.ext.commands
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: meta.py From discordbot.py with MIT License | 7 votes |
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)
Example #2
Source File: farmer_game.py From code-jam-5 with MIT License | 6 votes |
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)
Example #3
Source File: unlocks.py From code-jam-5 with MIT License | 5 votes |
def has_unlocked(name): async def pred(ctx): unlock = ctx.db.get_unlock_by_name(name) if not unlock.is_unlocked: raise commands.CheckFailure(unlock_message(name)) return True return commands.check(pred)
Example #4
Source File: treefinder.py From code-jam-5 with MIT License | 5 votes |
def cog_command_error(self, ctx, error): """Error handler for the cog; returns errors to the user if required. """ if isinstance(error, commands.CheckFailure): return await ctx.send(str(error))
Example #5
Source File: trivia.py From code-jam-5 with MIT License | 5 votes |
def cog_command_error(self, ctx, error): if isinstance(error, (commands.BadArgument, commands.CheckFailure)): return await ctx.send(str(error)) if isinstance(error, commands.BadUnionArgument): await ctx.send('Error encountered with parameters passed! ' 'Please see examples for help...') return await ctx.send_help(ctx.command)
Example #6
Source File: climate_arguments.py From code-jam-5 with MIT License | 5 votes |
def cog_command_error(self, ctx, error): """Error handler for the cog; returns errors to the user if required. """ if isinstance(error, (commands.BadArgument, commands.MissingRequiredArgument, commands.CheckFailure) ): return await ctx.send(str(error))
Example #7
Source File: rankings.py From code-jam-5 with MIT License | 5 votes |
def cog_command_error(self, ctx, error): """Error handler for the cog; returns errors to the user if required. """ if isinstance(error, commands.CheckFailure): return await ctx.send(str(error))
Example #8
Source File: farmer_game.py From code-jam-5 with MIT License | 5 votes |
def cog_command_error(self, ctx, error): if isinstance(error, (commands.BadArgument, commands.MissingRequiredArgument, commands.CheckFailure)): await ctx.send(str(error)) try: await ctx.db_stats.remove_last_used() except AttributeError: # command wasn't decorated with `@requires_account` pass
Example #9
Source File: converter.py From EmoteCollector with GNU Affero General Public License v3.0 | 5 votes |
def _check_reaction_permissions(context, channel): # author might not be a Member, even in a guild, if it's a webhook. if not context.guild or not isinstance(context.author, discord.Member): return sender_permissions = channel.permissions_for(context.author) permissions = channel.permissions_for(context.guild.me) if not sender_permissions.read_message_history or not permissions.read_message_history: raise commands.CheckFailure(_('Unable to react: you and I both need permission to read message history.')) if not sender_permissions.add_reactions or not permissions.add_reactions: raise commands.CheckFailure(_('Unable to react: you and I both need permission to add reactions.')) if not sender_permissions.external_emojis or not permissions.external_emojis: raise commands.CheckFailure(_('Unable to react: you and I both need permission to use external emotes.'))
Example #10
Source File: farmer_game.py From code-jam-5 with MIT License | 5 votes |
def requires_account(): """Command check to ensure the user has registered an account with the bot to play FarmerTown. """ async def pred(ctx): db_stats = await ctx.db.get_farmertown(ctx.author.id) if not db_stats: raise commands.CheckFailure('Account not found! ' 'Please register with `>farmertown create`') ctx.db_stats = db_stats return True return commands.check(pred)
Example #11
Source File: add_kills.py From Firetail with MIT License | 5 votes |
def _add_kills_error(self, ctx, error): if isinstance(error, commands.CheckFailure): return await ctx.channel.send('Only channel moderators can do that.')
Example #12
Source File: brain.py From RoleBot with GNU Affero General Public License v3.0 | 5 votes |
def p_error(error, ctx): if isinstance(error, commands.BadArgument): await bot.say("That\'s not a number...") if isinstance(error, commands.CheckFailure): await bot.say("Insufficent permissions")
Example #13
Source File: pollmaster.py From pollmaster with MIT License | 5 votes |
def on_command_error(ctx, e): if hasattr(ctx.cog, 'qualified_name') and ctx.cog.qualified_name == "Admin": # Admin cog handles the errors locally return if SETTINGS.log_errors: ignored_exceptions = ( commands.MissingRequiredArgument, commands.CommandNotFound, commands.DisabledCommand, commands.BadArgument, commands.NoPrivateMessage, commands.CheckFailure, commands.CommandOnCooldown, commands.MissingPermissions, discord.errors.Forbidden, ) if isinstance(e, ignored_exceptions): # log warnings # logger.warning(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') return # log error logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) if SETTINGS.msg_errors: # send discord message for unexpected errors e = discord.Embed( title=f"Error With command: {ctx.command.name}", description=f"```py\n{type(e).__name__}: {str(e)}\n```\n\nContent:{ctx.message.content}" f"\n\tServer: {ctx.message.server}\n\tChannel: <#{ctx.message.channel}>" f"\n\tAuthor: <@{ctx.message.author}>", timestamp=ctx.message.timestamp ) await ctx.send(bot.owner, embed=e) # if SETTINGS.mode == 'development': raise e
Example #14
Source File: admin.py From pollmaster with MIT License | 5 votes |
def cog_command_error(self, ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send("Only the owner can use this module. Join the support discord server if you are having " "any problems. This usage has been logged.") logger.warning(f'User {ctx.author} ({ctx.author.id}) has tried to access a restricted ' f'command via {ctx.message.content}.') elif isinstance(error, commands.MissingRequiredArgument): await ctx.send("Missing a required argument for this command.") else: logger.warning(error)
Example #15
Source File: core.py From NabBot with Apache License 2.0 | 5 votes |
def process_check_failure(cls, ctx: context.NabCtx, error: commands.CheckFailure): """Handles CheckFailure errors. These are exceptions that may be raised when executing command checks.""" if isinstance(error, (commands.NoPrivateMessage, errors.NotTracking, errors.UnathorizedUser, commands.MissingPermissions)): await ctx.error(error) elif isinstance(error, errors.CannotEmbed): await ctx.error(f"Sorry, `Embed Links` permission is required for this command.")
Example #16
Source File: core.py From NabBot with Apache License 2.0 | 5 votes |
def on_command_error(self, ctx: context.NabCtx, error: commands.CommandError): """Handles command errors""" if isinstance(error, commands.errors.CommandNotFound): return elif isinstance(error, commands.CommandOnCooldown): await ctx.error(f"You're using this too much! " f"Try again {timing.HumanDelta.from_seconds(error.retry_after).long(1)}.") elif isinstance(error, commands.CheckFailure): await self.process_check_failure(ctx, error) elif isinstance(error, commands.UserInputError): await self.process_user_input_error(ctx, error) elif isinstance(error, commands.CommandInvokeError): await self.process_command_invoke_error(ctx, error) else: log.warning(f"Unhandled command error {error.__class__.__name__}: {error}")
Example #17
Source File: checks.py From EmoteCollector with GNU Affero General Public License v3.0 | 5 votes |
def is_moderator(): async def predicate(context): db = context.bot.cogs['Database'] if not await db.is_moderator(context.author.id): raise commands.CheckFailure(_('You must be an emote moderator to run this command.')) return True return commands.check(predicate)
Example #18
Source File: bot.py From modmail with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #19
Source File: admin.py From sudoBot with GNU General Public License v3.0 | 5 votes |
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))
Example #20
Source File: admin.py From sudoBot with GNU General Public License v3.0 | 5 votes |
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))
Example #21
Source File: checks.py From avrae with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: checks.py From avrae with GNU General Public License v3.0 | 5 votes |
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)
Example #23
Source File: checks.py From avrae with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: checks.py From avrae with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: checks.py From avrae with GNU General Public License v3.0 | 5 votes |
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)
Example #26
Source File: core.py From spirit with MIT License | 5 votes |
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()
Example #27
Source File: fitwide.py From rubbergod with GNU General Public License v3.0 | 5 votes |
def fitwide_checks_error(self, ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send('Nothing to see here comrade. ' + '<:KKomrade:484470873001164817>')
Example #28
Source File: karma.py From rubbergod with GNU General Public License v3.0 | 5 votes |
def karma_error(self, ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send(utils.fill_message("insufficient_rights", user=ctx.author.id))
Example #29
Source File: admin.py From sudoBot with GNU General Public License v3.0 | 5 votes |
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))
Example #30
Source File: review.py From rubbergod with GNU General Public License v3.0 | 5 votes |
def review_error(self, ctx, error): if isinstance(error, commands.BadArgument): await ctx.send(messages.review_add_format) if isinstance(error, commands.CheckFailure): await ctx.send(utils.fill_message("insufficient_rights", user=ctx.author.id))