diff --git a/Events/MessageEvent.cs b/Events/MessageEvent.cs index da3c07fe..8ef2b88b 100644 --- a/Events/MessageEvent.cs +++ b/Events/MessageEvent.cs @@ -112,7 +112,10 @@ static async Task DeleteAndWarnAsync(MockDiscordMessage message, string reason, _ = message.DeleteAsync(); else if (channel.Type is DiscordChannelType.GuildForum) - channel = await client.GetChannelAsync(Program.cfgjson.ForumChannelAutoWarnFallbackChannel); + if (Program.cfgjson.ForumChannelAutoWarnFallbackChannel == 0) + 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.", channel.Id); + else + channel = Program.ForumChannelAutoWarnFallbackChannel; try { @@ -147,7 +150,8 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe if (wasAutoModBlock) { Program.discord.Logger.LogDebug("Processing AutoMod-blocked message in {channelId} by user {userId}", channel.Id, message.Author.Id); - if (channel.Type == DiscordChannelType.GuildForum) channel = await client.GetChannelAsync(Program.cfgjson.ForumChannelAutoWarnFallbackChannel); + if (channel.Type == DiscordChannelType.GuildForum && Program.cfgjson.ForumChannelAutoWarnFallbackChannel != 0) + channel = Program.ForumChannelAutoWarnFallbackChannel; } else { diff --git a/Program.cs b/Program.cs index 7c22bcad..e1597cf1 100644 --- a/Program.cs +++ b/Program.cs @@ -62,6 +62,8 @@ class Program : BaseCommandModule static public readonly HttpClient httpClient = new(); public static List serverApiList = new(); + + public static DiscordChannel ForumChannelAutoWarnFallbackChannel; public static void UpdateLists() { @@ -237,6 +239,9 @@ static async Task Main(string[] _) await discord.ConnectAsync(); await ReadyEvent.OnStartup(discord); + + if (cfgjson.ForumChannelAutoWarnFallbackChannel != 0) + ForumChannelAutoWarnFallbackChannel = await discord.GetChannelAsync(cfgjson.ForumChannelAutoWarnFallbackChannel); // Only wait 3 seconds before the first set of tasks. await Task.Delay(3000); diff --git a/Structs.cs b/Structs.cs index 0a024a0e..abf477df 100644 --- a/Structs.cs +++ b/Structs.cs @@ -300,7 +300,7 @@ public class ConfigJson public bool VoiceChannelPurge { get; private set; } = true; [JsonProperty("forumChannelAutoWarnFallbackChannel")] - public ulong ForumChannelAutoWarnFallbackChannel { get; private set; } + public ulong ForumChannelAutoWarnFallbackChannel { get; private set; } = 0; } public enum Level { Information, Warning, Error, Debug, Verbose }