-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (67 loc) · 2.24 KB
/
Program.cs
File metadata and controls
76 lines (67 loc) · 2.24 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
namespace DiscordTest
{
public class Program
{
private readonly DiscordSocketClient _client;
private IConfiguration _config;
private readonly CommandHandler _commandHandler;
private readonly CommandService _commands;
private readonly IServiceProvider _services;
public async static Task Main(string[] args)
{
Program prog = new Program();
await prog.MainAsync();
}
public Program()
{
_client = new DiscordSocketClient();
_config = BuildConfig();
_client.Log += Log;
_commands = new CommandService(new CommandServiceConfig()
{
CaseSensitiveCommands = false
});
_services = ConfigureServices();
_commandHandler = new CommandHandler(_client, _commands, _services);
}
public async Task MainAsync()
{
await _commandHandler.InstallCommandsAsync();
// Remember to keep token private or to read it from an
// external source! In this case, we are reading the token
// from an environment variable. If you do not know how to set-up
// environment variables, you may find more information on the
// Internet or by using other methods such as reading from
// a configuration.
await _client.LoginAsync(TokenType.Bot, _config["token"]);
await _client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
private static IServiceProvider ConfigureServices()
{
var map = new ServiceCollection();
return map.BuildServiceProvider();
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
private IConfiguration BuildConfig()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json")
.Build();
}
}
}