better DiscordBot channel exceptions

currently it always outputs `Failed to get log channel \"{Config.CommandChannel}\"` regardless if the error was with the command channel or the log channel.

await Run(); doesn't need to be in a try-catch block, because it has a try-catch block itself in it.
This commit is contained in:
Robin C. Ladiges 2022-09-07 16:23:55 +02:00 committed by Sanae
parent c41499f953
commit 92d4bdd195
1 changed files with 26 additions and 14 deletions

View File

@ -39,22 +39,34 @@ public class DiscordBot {
} }
private async void SettingsLoadHandler() { private async void SettingsLoadHandler() {
try { if (DiscordClient == null || Token != Config.Token) {
if (DiscordClient == null || Token != Config.Token)
await Run(); await Run();
//CommandChannel not currently used }
if (Config.CommandChannel != null)
CommandChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.CommandChannel)) ?? if (DiscordClient == null) {
throw new NullReferenceException("Discord client not setup yet!")); Logger.Error(new NullReferenceException("Discord client not setup yet!"));
if (Config.LogChannel != null) return;
LogChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.LogChannel)) ?? }
throw new NullReferenceException("Discord client not setup yet!"));
if (Config.CommandChannel != null) {
try {
CommandChannel = await DiscordClient.GetChannelAsync(ulong.Parse(Config.CommandChannel));
} catch (Exception e) { } catch (Exception e) {
Logger.Error($"Failed to get log channel \"{Config.CommandChannel}\""); Logger.Error($"Failed to get command channel \"{Config.CommandChannel}\"");
Logger.Error(e); Logger.Error(e);
} }
} }
if (Config.LogChannel != null) {
try {
LogChannel = await DiscordClient.GetChannelAsync(ulong.Parse(Config.LogChannel));
} catch (Exception e) {
Logger.Error($"Failed to get log channel \"{Config.LogChannel}\"");
Logger.Error(e);
}
}
}
private static List<string> SplitMessage(string message, int maxSizePerElem = 2000) private static List<string> SplitMessage(string message, int maxSizePerElem = 2000)
{ {
List<string> result = new List<string>(); List<string> result = new List<string>();