-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.cs
56 lines (47 loc) · 1.88 KB
/
Bot.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
48
49
50
51
52
53
54
55
56
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
using HyBot.Commands;
using Newtonsoft.Json;
namespace HyBot {
public class Bot {
public DiscordClient Client { get; private set; }
public InteractivityExtension Interactivity { get; private set; }
public CommandsNextExtension Commands { get; private set; }
public async Task RunAsync() {
var json = string.Empty;
using (var fs = File.OpenRead("config.json"))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = await sr.ReadToEndAsync();
var configJson = JsonConvert.DeserializeObject<ConfigJSON>(json);
var config = new DiscordConfiguration()
{
Token = configJson.Token,
TokenType = TokenType.Bot,
AutoReconnect = true,
};
Client = new DiscordClient(config);
Client.UseInteractivity(new InteractivityConfiguration()
{
Timeout = TimeSpan.FromMinutes(2)
});
var slashCommandsConfig = Client.UseSlashCommands();
slashCommandsConfig.RegisterCommands<PingCommand>();
slashCommandsConfig.RegisterCommands<InfoCommand>();
slashCommandsConfig.RegisterCommands<ClearCommand>();
slashCommandsConfig.RegisterCommands<SuggestCommand>();
slashCommandsConfig.RegisterCommands<CalculateCommand>();
slashCommandsConfig.RegisterCommands<PollCommand>();
await Client.ConnectAsync();
await Task.Delay(-1);
}
private Task OnClientReady(ReadyEventArgs e) {
return Task.CompletedTask;
}
}
}