From c7ed5599b4c2a4121b887832e8189fed6a4e7262 Mon Sep 17 00:00:00 2001 From: ddorn Date: Mon, 27 Apr 2020 22:26:04 +0200 Subject: [PATCH] :speech_balloon: better missing command message + allow commads to start with "! " --- src/tfjm_discord_bot.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tfjm_discord_bot.py b/src/tfjm_discord_bot.py index 8d9be98..afe07d2 100644 --- a/src/tfjm_discord_bot.py +++ b/src/tfjm_discord_bot.py @@ -13,7 +13,9 @@ from src.cogs import TfjmHelpCommand from src.constants import * from src.errors import TfjmError, UnwantedCommand -bot = commands.Bot("!", help_command=TfjmHelpCommand()) +# We allow "! " to catch people that put a space in their commands. +# It must be in first otherwise "!" always match first and the space is not recognised +bot = commands.Bot(("! ", "!"), help_command=TfjmHelpCommand()) # Variable globale qui contient les tirages. tirages = {} @@ -90,6 +92,11 @@ async def on_command_error(ctx: Context, error, *args, **kwargs): else: msg = str(error.original) or str(error) traceback.print_tb(error.original.__traceback__, file=sys.stderr) + elif isinstance(error, commands.CommandNotFound): + # Here we just take adventage that the error is formatted this way: + # 'Command "NAME" is not found' + name = str(error).partition('"')[2].rpartition('"')[0] + msg = f"La commande {name} n'éxiste pas. Pour un liste des commandes, envoie `!help`." else: msg = str(error)