- A basic working bot with a logging method as described in [Creating your first bot]: xref:Guides.GettingStarted.FirstBot#creating-a-discord-client
- A basic working bot with a logging method as described in [Creating your first bot](xref:Guides.GettingStarted.FirstBot)
## Installing the Serilog package
@@ -23,9 +23,13 @@ You can install the following packages through your IDE or go to the nuget link
Serilog will be configured at the top of your async Main method, it looks like this
```cs
using Discord;
using Serilog;
using Serilog.Events;
public class Program
{
public static Task Main(string[] args) => new Program().MainAsync();
public static Task Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
@@ -45,15 +49,15 @@ public class Program
// Some alternative options would be to keep your token in an Environment Variable or a standalone file.
// var token = Environment.GetEnvironmentVariable("NameOfYourEnvironmentVariable");
// var token = File.ReadAllText("token.txt");
// var token = File.ReadAllText("token.txt")[0];
// var token = JsonConvert.DeserializeObject<AConfigurationClass>(File.ReadAllText("config.json")).Token;
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
await Task.Delay(Timeout.Infinite);
}
}
```
@@ -62,7 +66,7 @@ public class Program
For serilog to log discord events correctly, we have to map the discord `LogSeverity` to the serilog `LogEventLevel`. You can modify your log method to look like this.
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.