-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.cs
More file actions
77 lines (56 loc) · 2.32 KB
/
Bot.cs
File metadata and controls
77 lines (56 loc) · 2.32 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
77
using DSharpPlus.Interactivity;
using DSharpPlus.SlashCommands;
using DSharpPlus;
using System.Text;
using Newtonsoft.Json;
using DSharpPlus.Interactivity.Extensions;
using ArcTicketBot.Commands;
using DSharpPlus.EventArgs;
namespace ArcTicketBot {
internal class Bot {
public DiscordClient? Client { get; private set; }
public InteractivityExtension? Interactivity { get; private set; }
public SlashCommandsExtension? Slash { get; private set; }
public async Task RunAsync() {
//Pull Token
var json = string.Empty;
using (var fileReader = File.OpenRead("config.json"))
using (var streamReader = new StreamReader(fileReader, new UTF8Encoding(false)))
json = await streamReader.ReadToEndAsync();
var configJson = JsonConvert.DeserializeObject<ConfigJson>(json);
//Discord Configuration
var config = new DiscordConfiguration {
Token = configJson.Token,
TokenType = TokenType.Bot,
AutoReconnect = true,
Intents = DiscordIntents.All,
LogUnknownAuditlogs = false,
LogUnknownEvents = false
};
//Event Registering
Client = new DiscordClient(config);
Client.ComponentInteractionCreated += OnComponentInteraction;
//Interactivity Setup
Client.UseInteractivity(new InteractivityConfiguration {
Timeout = TimeSpan.FromMinutes(5)
});
//Slash Command Registering
Slash = Client.UseSlashCommands();
try {
Slash.RegisterCommands<SetupCommands>();
Slash.RegisterCommands<TicketCommands>();
}catch (Exception ex) {
Console.WriteLine(ex.Message);
}
//Connect to Discord
await Client.ConnectAsync();
//Run Indefinitely
await Task.Delay(-1);
}
public async Task OnComponentInteraction(DiscordClient sender, ComponentInteractionCreateEventArgs e) {
var ticketInstance = new TicketCommands();
_ = Task.Run(() => ticketInstance.TicketButtonInteractions(sender, e.Guild, e));
await Task.CompletedTask;
}
}
}