From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.100]) by gnuweeb.org (Postfix) with ESMTPSA id D22E380C32; Sun, 11 Sep 2022 10:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662892445; bh=NtiuqWUy/GgVOpr9aM6mgMy1G4JjERB94+xAWDxVEgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KfjsIPV6vTLR9b0sh9NpzGOFQgq92kTAt+sBYEFVnsVIlpNpIa9LG5GLO+Rzgi3A0 Y0HnqE5kxVjsKgQ2DyQXxwDB+ItgSKisewE8xpRD0Yd+P3GA/NYILftGHBzm1e6i6f AMuoK6DQ2l90dX3xomVgHloxolZrQ4rOuCtDL3IIoreil+zhB9E9ghEcCIsT/NHRsl XvnSE/ycmF6vDkgvAyLo7ZqZt4KzbNEtpzcWMalf2X353TiwDEs/BesowgnIClbCHN 7mXBu0NTfX5oaenTbteGcBt3vCq8q3X+Rcrnkx6X/bp1lVAj7l//2cZ5aKAKAMpdil eiZNOmuYSe8TQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v1 10/17] [discord] Add error handler on events Date: Sun, 11 Sep 2022 17:33:16 +0700 Message-Id: <20220911103323.1949-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220911103323.1949-1-kiizuha@gnuweeb.org> References: <20220911103323.1949-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I added error handler to ignore command not found error while someone sending a message that is not exists for Discord basic commands. See image: https://i.ibb.co/qRcCz6Z/image.png Signed-off-by: Muhammad Rizki --- .../dscord/gnuweeb/plugins/events/__init__.py | 2 ++ .../dscord/gnuweeb/plugins/events/on_error.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 daemon/dscord/gnuweeb/plugins/events/on_error.py diff --git a/daemon/dscord/gnuweeb/plugins/events/__init__.py b/daemon/dscord/gnuweeb/plugins/events/__init__.py index d9a891f..7074e4d 100644 --- a/daemon/dscord/gnuweeb/plugins/events/__init__.py +++ b/daemon/dscord/gnuweeb/plugins/events/__init__.py @@ -4,8 +4,10 @@ # from .on_ready import OnReady +from .on_error import OnError class Events( OnReady, + OnError ): pass diff --git a/daemon/dscord/gnuweeb/plugins/events/on_error.py b/daemon/dscord/gnuweeb/plugins/events/on_error.py new file mode 100644 index 0000000..e1e4e28 --- /dev/null +++ b/daemon/dscord/gnuweeb/plugins/events/on_error.py @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from discord.ext import commands + + +class OnError(commands.Cog): + def __init__(self, bot: "commands.Bot") -> None: + self.bot = bot + + + @commands.Cog.listener() + async def on_command_error(self, _, err): + if isinstance(err, commands.CommandNotFound): + pass -- Muhammad Rizki