Improved 'Token not found' error message

This commit is contained in:
Stone-Red-Code
2021-02-12 19:27:54 +01:00
parent 508a1f6a99
commit aae747f49d
8 changed files with 9 additions and 8 deletions
Binary file not shown.
+9 -8
View File
@@ -9,8 +9,7 @@ namespace Discord_Simple_Embed_Bot
{ {
public class Program public class Program
{ {
public static void Main() public static void Main() => new Program().MainAsync().GetAwaiter().GetResult();
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync() public async Task MainAsync()
{ {
@@ -21,13 +20,14 @@ namespace Discord_Simple_Embed_Bot
string token = File.ReadAllText(tokenPath); string token = File.ReadAllText(tokenPath);
if (string.IsNullOrWhiteSpace(token)) if (string.IsNullOrWhiteSpace(token))
{ {
await Logging.Log(new LogMessage(LogSeverity.Critical, "Main", "Please put the Bot-Token into: " + tokenPath)); await Logging.Log(new LogMessage(LogSeverity.Critical, "Main", "", new ArgumentNullException("Token", $"Bot-Token not found! Put the Bot-Token into: '{tokenPath}'")));
return; return;
} }
DiscordSocketClient _client = new DiscordSocketClient(); DiscordSocketClient _client = new DiscordSocketClient();
_client.Log += Logging.Log; _client.Log += Logging.Log;
_client.MessageReceived += Client_MessageReceived; _client.MessageReceived += Client_MessageReceived;
try try
{ {
await _client.LoginAsync(TokenType.Bot, token, false); await _client.LoginAsync(TokenType.Bot, token, false);
@@ -42,8 +42,6 @@ namespace Discord_Simple_Embed_Bot
//Block this task until the program is closed. //Block this task until the program is closed.
await Task.Delay(-1); await Task.Delay(-1);
} }
private async Task Client_MessageReceived(SocketMessage messageParam) private async Task Client_MessageReceived(SocketMessage messageParam)
@@ -56,9 +54,12 @@ namespace Discord_Simple_Embed_Bot
{ {
public static Task Log(LogMessage msg) public static Task Log(LogMessage msg)
{ {
Console.ForegroundColor = GetColor(msg.Severity); lock (Console.Out)
Console.WriteLine(msg.ToString()); {
Console.ResetColor(); Console.ForegroundColor = GetColor(msg.Severity);
Console.WriteLine(msg.ToString());
Console.ResetColor();
}
return Task.CompletedTask; return Task.CompletedTask;
} }