Skip to content

Commit

Permalink
Try not to NRE on message delete events
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jul 28, 2024
1 parent 01d6ef0 commit c572f6b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ public static async Task MessageUpdated(DiscordClient client, MessageUpdatedEven

public static async Task MessageDeleted(DiscordClient client, MessageDeletedEventArgs e)
{
client.Logger.LogDebug("Got a message delete event for {message} by {user}", DiscordHelpers.MessageLink(e.Message), e.Message.Author.Id);

if (e.Message is null)
{
client.Logger.LogDebug("Got a message delete event but the message was null!");
} else if (e.Message.Author is null)
{
client.Logger.LogDebug("Got a message delete event for a message with no author: {message}", DiscordHelpers.MessageLink(e.Message));
} else
{
client.Logger.LogDebug("Got a message delete event for {message} by {user}", DiscordHelpers.MessageLink(e.Message), e.Message.Author.Id);
}

// Delete thread if all messages are deleted
if (Program.cfgjson.AutoDeleteEmptyThreads && e.Channel is DiscordThreadChannel)
{
Expand Down

0 comments on commit c572f6b

Please sign in to comment.