Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly catch, print and log errors when banning a user with .ban or .banall #496

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)");
}
Comment on lines +234 to +246

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

if (time != null)
{
Expand Down
Loading