Python discord.ext.commands.CommandOnCooldown() Examples
The following are 10
code examples of discord.ext.commands.CommandOnCooldown().
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
.
Example #1
Source File: bot.py From RemixBot with MIT License | 6 votes |
def on_command_error(ctx, error): send_help = (commands.MissingRequiredArgument, commands.BadArgument, commands.TooManyArguments, commands.UserInputError) if isinstance(error, commands.CommandNotFound): # fails silently pass elif isinstance(error, send_help): _help = await send_cmd_help(ctx) await ctx.send(embed=_help) elif isinstance(error, commands.CommandOnCooldown): await ctx.send(f'This command is on cooldown. Please wait {error.retry_after:.2f}s') elif isinstance(error, commands.MissingPermissions): await ctx.send('You do not have the permissions to use this command.') # If any other error occurs, prints to console. else: print(''.join(traceback.format_exception(type(error), error, error.__traceback__)))
Example #2
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 #3
Source File: base.py From rubbergod with GNU General Public License v3.0 | 5 votes |
def on_command_error(self, ctx, error): # The local handlers so far only catch bad arguments so we still # want to print the rest if (isinstance(error, commands.BadArgument) or isinstance(error, commands.errors.CheckFailure) or isinstance(error, commands.errors.MissingAnyRole) or isinstance(error, commands.errors.MissingRequiredArgument)) and\ hasattr(ctx.command, 'on_error'): return if isinstance(error, commands.UserInputError): await ctx.send("Chyba v inputu") return if isinstance(error, commands.CommandNotFound): prefix = ctx.message.content[:1] if prefix not in config.ignored_prefixes: await ctx.send(messages.no_such_command) return if isinstance(error, commands.CommandOnCooldown): await ctx.send(utils.fill_message("spamming", user=ctx.author.id)) return output = 'Ignoring exception in command {}:\n'.format(ctx.command) output += ''.join(traceback.format_exception(type(error), error, error.__traceback__)) channel = self.bot.get_channel(config.bot_dev_channel) print(output) output = utils.cut_string(output, 1900) if channel is not None: for message in output: await channel.send("```\n" + message + "\n```")
Example #4
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 #5
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 #6
Source File: bot.py From Dozer with GNU General Public License v3.0 | 5 votes |
def on_command_error(self, context, exception): if isinstance(exception, commands.NoPrivateMessage): await context.send('{}, This command cannot be used in DMs.'.format(context.author.mention)) elif isinstance(exception, commands.UserInputError): await context.send('{}, {}'.format(context.author.mention, self.format_error(context, exception))) elif isinstance(exception, commands.NotOwner): await context.send('{}, {}'.format(context.author.mention, exception.args[0])) elif isinstance(exception, commands.MissingPermissions): permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in exception.missing_perms] await context.send('{}, you need {} permissions to run this command!'.format( context.author.mention, utils.pretty_concat(permission_names))) elif isinstance(exception, commands.BotMissingPermissions): permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in exception.missing_perms] await context.send('{}, I need {} permissions to run this command!'.format( context.author.mention, utils.pretty_concat(permission_names))) elif isinstance(exception, commands.CommandOnCooldown): await context.send( '{}, That command is on cooldown! Try again in {:.2f}s!'.format(context.author.mention, exception.retry_after)) elif isinstance(exception, (commands.CommandNotFound, InvalidContext)): pass # Silent ignore else: await context.send('```\n%s\n```' % ''.join(traceback.format_exception_only(type(exception), exception)).strip()) if isinstance(context.channel, discord.TextChannel): DOZER_LOGGER.error('Error in command <%d> (%d.name!r(%d.id) %d(%d.id) %d(%d.id) %d)', context.command, context.guild, context.guild, context.channel, context.channel, context.author, context.author, context.message.content) else: DOZER_LOGGER.error('Error in command <%d> (DM %d(%d.id) %d)', context.command, context.channel.recipient, context.channel.recipient, context.message.content) DOZER_LOGGER.error(''.join(traceback.format_exception(type(exception), exception, exception.__traceback__)))
Example #7
Source File: general.py From cyberdisc-bot with MIT License | 4 votes |
def on_command_error(self, ctx, error): # Try provide some user feedback instead of logging all errors. if isinstance(error, commands.CommandNotFound): return # No need to log unfound commands anywhere or return feedback if isinstance(error, commands.MissingRequiredArgument): # Missing arguments are likely human error so do not need logging parameter_name = error.param.name return await ctx.send( f"\N{NO ENTRY SIGN} Required argument {parameter_name} was missing" ) elif isinstance(error, commands.CheckFailure): return await ctx.send( "\N{NO ENTRY SIGN} You do not have permission to use that command" ) elif isinstance(error, commands.CommandOnCooldown): retry_after = round(error.retry_after) return await ctx.send( f"\N{HOURGLASS} Command is on cooldown, try again after {retry_after} seconds" ) # All errors below this need reporting and so do not return if isinstance(error, commands.ArgumentParsingError): # Provide feedback & report error await ctx.send( "\N{NO ENTRY SIGN} An issue occurred while attempting to parse an argument" ) elif isinstance(error, commands.BadArgument): await ctx.send("\N{NO ENTRY SIGN} Conversion of an argument failed") else: await ctx.send( "\N{NO ENTRY SIGN} An error occured during execution, the error has been reported." ) extra_context = { "discord_info": { "Channel": ctx.channel.mention, "User": ctx.author.mention, "Command": ctx.message.content, } } if ctx.guild is not None: # We are NOT in a DM extra_context["discord_info"]["Message"] = ( f"[{ctx.message.id}](https://discordapp.com/channels/" f"{ctx.guild.id}/{ctx.channel.id}/{ctx.message.id})" ) else: extra_context["discord_info"]["Message"] = f"{ctx.message.id} (DM)" self.bot.log.exception(error, extra=extra_context)
Example #8
Source File: error_handler.py From RTFMbot with Mozilla Public License 2.0 | 4 votes |
def _on_command_error(self, ctx, error, bypass = False): name, content = None, None raised = False if hasattr(ctx.command, 'on_error') or (ctx.command and hasattr(ctx.cog, f'_{ctx.command.cog_name}__error')) and not bypass: # Do nothing if the command/cog has its own error handler and the bypass is False return if isinstance(error, commands.CommandInvokeError) and hasattr(error, 'original'): error = error.original raised = True if isinstance(error, commands.CommandNotFound) or isinstance(error, commands.NotOwner): return elif isinstance(error, commands.MissingRequiredArgument): name = "SyntaxError" content = f"Command `{ctx.command.name}` missing 1 required argument: `{error.param.name}`" elif isinstance(error, commands.BadArgument): name = "TypeError" content = str(error.args[0]) elif isinstance(error, commands.CommandOnCooldown): name = "TimeoutError" content = f"Command on cooldown. Retry in `{format(error.retry_after, '.2f')}s`." elif isinstance(error, commands.CheckFailure): name = "PermissionError" content = "Escalation failed: you are not in the sudoers file.\nThis incident will be reported" elif isinstance(error, discord.Forbidden) or isinstance(error, discord.HTTPException): # We may not be able to send an embed or even send a message at this point bot_member = ctx.guild.get_member(self.bot.user.id) can_talk = ctx.channel.permissions_for(bot_member).send_messages if can_talk: return await ctx.send(f"```An error occurred while responding:\n{error.code} - {error.text}\n\nI need following permissions:\n\nEmbed links\nAttach files\nAdd reactions```") elif isinstance(error, UnicodeError): name = "UnicodeError" content = "The bot failed to decode your input or a command output. Make sure you only use UTF-8" if name is not None: emb = discord.Embed(title=name, description=content, colour=self.bot.config['RED']) await ctx.send(embed=emb) elif raised: print(f'{time.strftime("%d/%m/%y %H:%M:%S")} | {ctx.command.qualified_name}', file=sys.stderr) traceback.print_tb(error.__traceback__) print(f'{error.__class__.__name__}: {error}', file=sys.stderr, end='\n\n') else: print(traceback.format_exc())
Example #9
Source File: handler.py From DJ5n4k3 with MIT License | 4 votes |
def on_command_error(self, ctx, error): if hasattr(ctx.command, 'on_error'): return ignored = (commands.MissingRequiredArgument, commands.BadArgument, commands.NoPrivateMessage, commands.CheckFailure, commands.CommandNotFound, commands.DisabledCommand, commands.CommandInvokeError, commands.TooManyArguments, commands.UserInputError, commands.CommandOnCooldown, commands.NotOwner, commands.MissingPermissions, commands.BotMissingPermissions) error = getattr(error, 'original', error) if isinstance(error, commands.CommandNotFound): return elif isinstance(error, commands.BadArgument): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.MissingRequiredArgument): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.NoPrivateMessage): return elif isinstance(error, commands.CheckFailure): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command is thought for other users. You can't use it.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.DisabledCommand): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command in disabled.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.CommandInvokeError): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like something went wrong. Report this issue to the developer.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.TooManyArguments): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you gave too many arguments.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.UserInputError): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you did something wrong.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.CommandOnCooldown): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.NotOwner): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you do not own this bot.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.MissingPermissions): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.BotMissingPermissions): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
Example #10
Source File: error_handler.py From code-jam-5 with MIT License | 4 votes |
def on_command_error(self, ctx, error): """Task when an error occurs.""" if isinstance(error, commands.CommandNotFound): return logger.info(f"{ctx.author} used {ctx.message.content} " f"but nothing was found.") if isinstance(error, commands.MissingRequiredArgument): logger.info(f"{ctx.author} called {ctx.message.content} and " f"triggered MissingRequiredArgument error.") return await ctx.send(f"`{error.param}` is a required argument.") if isinstance(error, commands.CheckFailure): logger.info(f"{ctx.author} called {ctx.message.content} and triggered" f" CheckFailure error.") return await ctx.send("You do not have permission to use this command!") if isinstance(error, (commands.UserInputError, commands.BadArgument)): logger.info(f"{ctx.author} called {ctx.message.content} and triggered" f" UserInputError error.") return await ctx.send("Invalid arguments.") if isinstance(error, commands.CommandOnCooldown): logger.info(f"{ctx.author} called {ctx.message.content} and" f" triggered ComamndOnCooldown error.") return await ctx.send(f"Command is on cooldown!" f" Please retry after `{error.retry_after}`") if isinstance(error, commands.BotMissingPermissions): logger.info(f"{ctx.author} called {ctx.message.content} and triggered" f" BotMissingPermissions error.") embed = discord.Embed() embed.colour = discord.Colour.blue() title = "The bot lacks the following permissions to execute the command:" embed.title = title embed.description = "" for perm in error.missing_perms: embed.description += str(perm) return await ctx.send(embed=embed) if isinstance(error, commands.DisabledCommand): logger.info(f"{ctx.author} called {ctx.message.content} and" f" triggered DisabledCommand error.") return await ctx.send("The command has been disabled!") logger.warning(f"{ctx.author} called {ctx.message.content} and" f" triggered the following error:\n {error}")