From b9ac88864c832e0283c4fdcb9041900533f8807b Mon Sep 17 00:00:00 2001 From: Skycloudd <51929172+Skycloudd@users.noreply.github.com> Date: Sun, 27 Sep 2020 12:06:57 +0200 Subject: add global error handler handles these errors: - CommandNotFound (does nothing) - CommandOnCooldown (does nothing) --- cogs/errorhandler.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cogs/errorhandler.py (limited to 'cogs/errorhandler.py') diff --git a/cogs/errorhandler.py b/cogs/errorhandler.py new file mode 100644 index 0000000..e3483c8 --- /dev/null +++ b/cogs/errorhandler.py @@ -0,0 +1,20 @@ +from discord.ext import commands + + +class Errorhandler(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_command_error(self, ctx, error): + if isinstance(error, commands.CommandNotFound): + return + + if isinstance(error, commands.CommandOnCooldown): + return + + raise error + + +def setup(bot): + bot.add_cog(Errorhandler(bot)) -- cgit v1.2.3 From 6666649bcb48f8251456064b4b28d34e57e2f43e Mon Sep 17 00:00:00 2001 From: Skycloudd <51929172+Skycloudd@users.noreply.github.com> Date: Sun, 27 Sep 2020 12:34:08 +0200 Subject: add cooldown message --- cogs/errorhandler.py | 2 +- cogs/utils.py | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) (limited to 'cogs/errorhandler.py') diff --git a/cogs/errorhandler.py b/cogs/errorhandler.py index e3483c8..8533a61 100644 --- a/cogs/errorhandler.py +++ b/cogs/errorhandler.py @@ -11,7 +11,7 @@ class Errorhandler(commands.Cog): return if isinstance(error, commands.CommandOnCooldown): - return + return await ctx.send(f'{ctx.author.mention}, you have to wait {round(error.retry_after, 2)} seconds before using this again') raise error diff --git a/cogs/utils.py b/cogs/utils.py index 3caca9e..1d3f3a8 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -366,14 +366,6 @@ class Utils(commands.Cog): "https://aninternettroll.github.io/mcbeVerifierLeaderboard/" ) - @leaderboard.error - async def leaderboard_handler(self, ctx, error): - if isinstance(error, commands.CommandOnCooldown): - # return - await ctx.send( - f"{discord.utils.escape_mentions(ctx.message.author.display_name)}, you have to wait {round(error.retry_after, 2)} seconds before using this again." - ) - @commands.cooldown(1, 60, commands.BucketType.guild) @commands.command() async def someone(self, ctx): -- cgit v1.2.3