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 7848F80D8A; Tue, 13 Sep 2022 10:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663064779; bh=A947FgQOZf+2VBEzsbkg0w6wb19N1k3Wx6zMyCjzot0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PLAUSJ7ZpNvB6HAZw4jn7f1HBMiC9at8QZgJNiW8UY9llUb+D9i8kYJikB+jNaS+W KpCeGlECrZqhYr30CS0NvW0gyAilp0uUkHg4kDkYsHF+KUcaovQYDfiMEJ2adEJZrl D1EuWBOWyTCYGonWxg1W9jD33XvIWjYAV2ab98iTTiLWjhLA8H4J/CNRDwFlexzu8y istVic03e5t27DBP0x86351vtWhkkfY07yfB65XJe7B/znSLkhZAusBAouAz+ROCB7 DCehWETYzw56Z/CdthWYGkIJ0wqFvQZNOdoiBQ7oI5bCp9JVAc2Fa+w1PU5dmZM0Bh s8r2dBFQcicjA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v2 10/17] discord: Add error handler on events Date: Tue, 13 Sep 2022 17:24:51 +0700 Message-Id: <20220913102458.615-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220913102458.615-1-kiizuha@gnuweeb.org> References: <20220913102458.615-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