Skip to content

Commit

Permalink
properly catch, print and log errors when banning a user with .ban or…
Browse files Browse the repository at this point in the history
… .banall
  • Loading branch information
Ixrec committed Nov 7, 2023
1 parent d83e881 commit 235b6f0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Izzy-Moonbot/Modules/ModCoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" +

Check failure on line 240 in Izzy-Moonbot/Modules/ModCoreModule.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'job' does not exist in the current context

Check failure on line 240 in Izzy-Moonbot/Modules/ModCoreModule.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The name 'job' does not exist in the current context
$"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)
{
Expand Down

0 comments on commit 235b6f0

Please sign in to comment.