From 235b6f0cbf456e6ee88055272f33c76490c16f21 Mon Sep 17 00:00:00 2001 From: ixrec Date: Tue, 7 Nov 2023 18:31:28 +0000 Subject: [PATCH] properly catch, print and log errors when banning a user with .ban or .banall --- Izzy-Moonbot/Modules/ModCoreModule.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Izzy-Moonbot/Modules/ModCoreModule.cs b/Izzy-Moonbot/Modules/ModCoreModule.cs index 4dfa5ec2..1fa72d55 100644 --- a/Izzy-Moonbot/Modules/ModCoreModule.cs +++ b/Izzy-Moonbot/Modules/ModCoreModule.cs @@ -227,7 +227,24 @@ await Context.Channel.SendMessageAsync( if (!hasExistingBan) { // No ban exists, very serious Izzy time. - await Context.Guild.AddBanAsync(userId, pruneDays: 0, reason: reason ); + try + { + await Context.Guild.AddBanAsync(userId, pruneDays: 0, reason: reason ); + } + catch (Exception ex) + { + _logger.Log( + $"AddBanAsync() threw an exception when trying to ban userId {userId}\n" + + $"Type: {ex.GetType().Name}\n" + + $"Message: {ex.Message}\n" + + $"Job: {job.ToFileString()}\n" + + $"Stack Trace: {ex.StackTrace}"); + + await Context.Channel.SendMessageAsync( + $":warning: Failed to ban userId {userId}\n" + + $"Error was: [{ex.GetType().Name}] {ex.Message}\n" + + $"(Check Izzy's logs for a full stack trace)"); + } if (time != null) {