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 CF44880E16; Mon, 19 Sep 2022 07:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663572443; bh=A947FgQOZf+2VBEzsbkg0w6wb19N1k3Wx6zMyCjzot0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DL9ac8KBQXMVA6+gsXVE6dslnTJWl6e6NdrST1hY+AFZ0Se9H+CAhgLiXtpZ0F2if X+tjWWJMVp206IvKBcIRFeEW6bSbjad9PY8/jNN84rDaBH5VT4HvephwySLUsatFhp lptuPdah9HyqDmSSKQFDe1P8PM62KO7XiSto3kC0sVKSO0n41m70YoJbvPJ+HMfxPM hOeBwuQU8rEiyvIqOO3RuK3khU0Qe73YWl0lL3e0hPYe6xa8dhL1dKhpCeuX2Z6u45 g3hyFMsV6cLyHNSUdDQZ0M0sQYup8dooeaDIReNd9EWDDHKxJYeT0uyNmPrjrrE47k 9fCpF4YDl1KKg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v3 10/17] discord: Add error handler on events Date: Mon, 19 Sep 2022 14:26:34 +0700 Message-Id: <20220919072641.996-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220919072641.996-1-kiizuha@gnuweeb.org> References: <20220919072641.996-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Adding error handler to ignore `CommandNotFound` error while someone sending a message that is not exists for the bot 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