-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJukeBoxService.cs
More file actions
34 lines (29 loc) · 914 Bytes
/
Copy pathJukeBoxService.cs
File metadata and controls
34 lines (29 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Discord;
using Discord.WebSocket;
namespace JukeBox;
public class JukeBoxService : IHostedService
{
private readonly DiscordSocketClient _client;
private readonly IConfiguration _config;
public JukeBoxService(DiscordSocketClient client, IConfiguration config)
{
_client = client;
_config = config;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
_client.Log += async Task (LogMessage msg) =>
{
Console.WriteLine(msg.Message);
await Task.CompletedTask;
};
var token = _config.GetRequiredSection("Token").Value;
await _client.LoginAsync(TokenType.Bot, token, validateToken: true);
await _client.StartAsync();
}
public async Task StopAsync(CancellationToken cancellationToken)
{
await _client.LogoutAsync();
await _client.StopAsync();
}
}