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,19 +39,31 @@ 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) if (DiscordClient == null) {
CommandChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.CommandChannel)) ?? Logger.Error(new NullReferenceException("Discord client not setup yet!"));
throw new NullReferenceException("Discord client not setup yet!")); return;
if (Config.LogChannel != null) }
LogChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.LogChannel)) ??
throw new NullReferenceException("Discord client not setup yet!")); if (Config.CommandChannel != null) {
} catch (Exception e) { try {
Logger.Error($"Failed to get log channel \"{Config.CommandChannel}\""); CommandChannel = await DiscordClient.GetChannelAsync(ulong.Parse(Config.CommandChannel));
Logger.Error(e); } catch (Exception e) {
Logger.Error($"Failed to get command channel \"{Config.CommandChannel}\"");
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);
}
} }
} }
@ -145,4 +157,4 @@ public class DiscordBot {
Logger.Error(e); Logger.Error(e);
} }
} }
} }