-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
47 lines (39 loc) · 1.38 KB
/
Program.cs
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 Discord;
using Discord.Commands;
using Discord.WebSocket;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MusicBot
{
public class Program
{
public static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
private DiscordSocketClient _client;
private CommandService _commands;
private CommandHandler _handler;
public async Task MainAsync()
{
_client = new DiscordSocketClient();
_commands = new CommandService();
_handler = new CommandHandler(_client, _commands);
// Install commands
await _handler.InstallCommandsAsync();
// Hook client log to to Log event handler from below
_client.Log += Log;
// Bot token stored in config.json
string token = JsonConvert.DeserializeObject<dynamic>(File.ReadAllText("config.json")).BotToken;
// Start up client
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
private Task Log(LogMessage msg)
{
Console.WriteLine($"[ {DateTime.Now,0:t} ] [{msg.Severity,8}] {msg.Message}");
return Task.CompletedTask;
}
}
}