-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandsUpdater.cs
68 lines (60 loc) · 1.64 KB
/
CommandsUpdater.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
using Discord;
using Discord.Net;
using Discord.WebSocket;
using Newtonsoft.Json;
using System.Data;
namespace DiscordBot
{
public static class CommandsUpdater
{
public static async Task UpdateAllGuildCommands(DiscordSocketClient client)
{
Dictionary<ulong, SlashCommand[]> guildsCommands = new()
{
// ulong: the id of the guild, SlashCommand[]: the commands you wish to be available for only that guild
};
try
{
foreach (var kvp in guildsCommands)
{
await UpdateGuildCommands(client, kvp.Key, kvp.Value);
}
} catch (HttpException) { }
}
public static async Task UpdateGuildCommands(DiscordSocketClient client, ulong guildId, SlashCommand[] guildCommands)
{
SocketGuild guild = client.GetGuild(guildId);
try
{
foreach (SlashCommand command in guildCommands)
{
await guild.CreateApplicationCommandAsync(command.Build());
Console.WriteLine($"guild '{guild.Name}' has had its command '{command.Name}' updated");
}
}
catch (HttpException e)
{
string json = JsonConvert.SerializeObject(e.Errors, Formatting.Indented);
Console.WriteLine(json);
}
}
public static async Task UpdateGlobalCommands(DiscordSocketClient client)
{
SlashCommand[] globalCommands = new SlashCommand[] {
};
try
{
foreach(SlashCommand command in globalCommands)
{
await client.CreateGlobalApplicationCommandAsync(command.Build());
Console.WriteLine($"command '{command.Name}' has been updated globally");
}
}
catch (HttpException e)
{
string json = JsonConvert.SerializeObject(e.Errors, Formatting.Indented);
Console.WriteLine(json);
}
}
}
}