From 72fe53051c4aadf704f1ace68bbb84f72c3e7a96 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Tue, 25 Mar 2025 19:39:47 +0500 Subject: [PATCH] automatically remove messages in old text command format --- CompatBot/Commands/Processors/CommandErroredHandler.cs | 9 ++++++++- CompatBot/Program.cs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CompatBot/Commands/Processors/CommandErroredHandler.cs b/CompatBot/Commands/Processors/CommandErroredHandler.cs index 2768aed4..0daa460c 100644 --- a/CompatBot/Commands/Processors/CommandErroredHandler.cs +++ b/CompatBot/Commands/Processors/CommandErroredHandler.cs @@ -1,6 +1,7 @@ using System.Net; using DSharpPlus.Commands.EventArgs; using DSharpPlus.Commands.Exceptions; +using DSharpPlus.Commands.Processors.TextCommands; using DSharpPlus.Exceptions; namespace CompatBot.Commands.Processors; @@ -10,9 +11,15 @@ internal static class CommandErroredHandler // CommandsExtension.DefaultCommandErrorHandlerAsync() public static async Task OnError(CommandsExtension sender, CommandErroredEventArgs eventArgs) { - StringBuilder stringBuilder = new(); + StringBuilder stringBuilder = new(); DiscordMessageBuilder messageBuilder = new(); + if (eventArgs is { Exception: CommandNotFoundException, Context: TextCommandContext tctx }) + { + await tctx.Message.DeleteAsync().ConfigureAwait(false); + return; + } + // Error message stringBuilder.Append(eventArgs.Exception switch { diff --git a/CompatBot/Program.cs b/CompatBot/Program.cs index 8a1cf02c..b10ce103 100644 --- a/CompatBot/Program.cs +++ b/CompatBot/Program.cs @@ -145,6 +145,8 @@ internal static class Program Config.CommandPrefix, Config.AutoRemoveCommandPrefix ).ResolvePrefixAsync, + IgnoreBots = true, + EnableCommandNotFoundException = true, }); var appCommandProcessor = new SlashCommandProcessor(new() {