mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-25 04:35:18 +00:00
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:
parent
c41499f953
commit
92d4bdd195
1 changed files with 26 additions and 14 deletions
|
@ -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>();
|
||||||
|
|
Loading…
Reference in a new issue