-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (39 loc) · 1.31 KB
/
Program.cs
File metadata and controls
47 lines (39 loc) · 1.31 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Discord.Commands;
using Microsoft.Extensions.DependencyInjection;
namespace capone
{
public class Program
{
private DiscordSocketClient _client;
private readonly string DiscordToken = new Keys().BotToken;
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
_client = new DiscordSocketClient();
_client.Log += Log;
var services = ConfigureServices();
await services.GetRequiredService<CommandHandler>().InstallCommandsAsync(services);
await _client.LoginAsync(TokenType.Bot, DiscordToken);
await _client.StartAsync();
await Task.Delay(-1);
}
private IServiceProvider ConfigureServices()
{
return new ServiceCollection()
.AddSingleton(_client)
.AddSingleton<CommandService>()
.AddSingleton<CommandHandler>()
.BuildServiceProvider();
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
}
}