Skip to content

Commit

Permalink
Merge pull request #496 from Ixrec/catch-ban-errors
Browse files Browse the repository at this point in the history
properly catch, print and log errors when banning a user with .ban or .banall
  • Loading branch information
Ixrec authored Nov 7, 2023
2 parents d83e881 + f93e82f commit d5d3e8d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Izzy-Moonbot/Modules/ModCoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,23 @@ 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" +
$"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 d5d3e8d

Please sign in to comment.