-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
81 lines (80 loc) · 2.78 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
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
78
79
80
81
using Discord;
using Discord.WebSocket;
using System.Diagnostics;
namespace AlphaTTS
{
public sealed class Program
{
DiscordSocketClient _client;
//Sealed means class can't be inherited
public static async Task Main()
{
//Static: Inheritor will not create an instance, It will do Program.Main()
var program = new Program();
await program.StartAsync();
}
private async Task StartAsync()
{
// _client = new DiscordSocketClient(new DiscordSocketConfig()
_client = new(new()
{
LogLevel = LogSeverity.Info
});
_client.Log += Log;
_client.Ready += ReadyAsync;
_client.SlashCommandExecuted += SlashCommandExecutedAsync;
await _client.LoginAsync(TokenType.Bot, File.ReadAllText("token.txt"));
await _client.StartAsync();
await Task.Delay(-1); // Wait forever
}
private Task Log(LogMessage msg)
{
// we'll quickly go on it
Console.WriteLine(msg);
return Task.CompletedTask;
}
private async Task SlashCommandExecutedAsync(SocketSlashCommand cmd)
{
var cmdName = cmd.CommandName.ToUpperInvariant();
if (cmdName == "PING")
{
await cmd.RespondAsync("Pong!");
}
}
private Task ReadyAsync()
{
// _ means variable is not gonna be used, so compiler stops whining
_ = Task.Run(async () => {
var builder = new[]
{
new SlashCommandBuilder()
{
Name = "ping",
Description = "Pings Alpha"
}
}.Select(x => x.Build()).ToArray();
foreach (var command in builder)
{
if (Debugger.IsAttached)
{
await _client.GetGuild(1237296137774567474).CreateApplicationCommandAsync(command);
}
else
{
await _client.CreateGlobalApplicationCommandAsync(command);
}
}
if (Debugger.IsAttached)
{
await _client.GetGuild(1237296137774567474).BulkOverwriteApplicationCommandAsync(builder);
}
else
{
await _client.GetGuild(1237296137774567474).DeleteApplicationCommandsAsync();
await _client.BulkOverwriteGlobalApplicationCommandsAsync(builder);
}
});
return Task.CompletedTask;
}
}
}