Skip to content

Commit 52030e0

Browse files
Fix thread channel auto-warn messages being sent to the wrong channel
Ensures that auto-warn messages are properly sent in a thread channel if it is not deleted
1 parent a89a9dd commit 52030e0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Helpers/WarningHelpers.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,26 @@ public static async Task<DiscordMessage> SendPublicWarningMessageAndDeleteInfrin
411411

412412
public static async Task<DiscordMessage> SendPublicWarningMessageAndDeleteInfringingMessageAsync(MockDiscordMessage infringingMessage, string warningMessageContent, bool wasAutoModBlock = false, int minMessages = 0)
413413
{
414-
// If this is a `GuildForum` channel, delete the thread if it is empty (empty = 1 message left if `isAutoWarn`, otherwise 0); if not empty, just delete the infringing message.
414+
// If this is a `GuildForum` channel, delete the thread if it is empty; if not empty, just delete the infringing message.
415415
// Then, based on whether the thread was deleted, send the warning message into the thread or into the configured fallback channel.
416+
// If this was an AutoMod block, don't delete anything.
416417
// Return the sent warning message for logging.
417418

418-
var targetChannel = infringingMessage.Channel;
419-
if (infringingMessage.Channel.Type == DiscordChannelType.GuildForum || infringingMessage.Channel.Parent.Type == DiscordChannelType.GuildForum)
419+
bool wasThreadDeleted = false;
420+
if (!wasAutoModBlock)
421+
wasThreadDeleted = await DiscordHelpers.ThreadChannelAwareDeleteMessageAsync(infringingMessage, minMessages);
422+
423+
DiscordChannel targetChannel = infringingMessage.Channel;
424+
if (wasThreadDeleted || targetChannel.Id == Program.cfgjson.SupportForumId)
420425
{
421426
if (Program.cfgjson.ForumChannelAutoWarnFallbackChannel == 0)
422427
Program.discord.Logger.LogWarning("A warning in forum channel {channelId} was attempted, but may fail due to the fallback channel not being set. Please set 'forumChannelAutoWarnFallbackChannel' in config.json to avoid this.", targetChannel.Id);
423428
else
424429
targetChannel = Program.ForumChannelAutoWarnFallbackChannel;
425430
}
426431

427-
if (!wasAutoModBlock)
428-
{
429-
if (await DiscordHelpers.ThreadChannelAwareDeleteMessageAsync(infringingMessage, minMessages))
430-
targetChannel = await Program.discord.GetChannelAsync(Program.cfgjson.ForumChannelAutoWarnFallbackChannel);
431-
}
432432
var warningMessage = await targetChannel.SendMessageAsync(warningMessageContent);
433433
return warningMessage;
434434
}
435-
436435
}
437436
}

0 commit comments

Comments
 (0)