|
| 1 | +using System; |
1 | 2 | using System.Collections.Generic; |
2 | 3 | using System.Linq; |
3 | 4 | using System.Threading.Tasks; |
@@ -82,17 +83,25 @@ private async Task ApplyCommandPermissions(DiscordSocketClient client, IEnumerab |
82 | 83 |
|
83 | 84 | private async Task UpdateModule(SlashCommandModule module) |
84 | 85 | { |
85 | | - module.BuildCommandHandlers(); |
| 86 | + var applicationCommands = await _client.Rest.GetGuildApplicationCommands(Settings.Current.GuildID); |
| 87 | + var handlers = module.BuildCommandHandlers(); |
86 | 88 |
|
87 | | - foreach (var command in await _client.Rest.GetGuildApplicationCommands(Settings.Current.GuildID)) |
88 | | - await command.DeleteAsync(); |
| 89 | + var commandsToUpdate = from handler in handlers |
| 90 | + let command = applicationCommands.FirstOrDefault(c => c.Name == handler.Name) |
| 91 | + where command != null |
| 92 | + select (handler, command); |
89 | 93 |
|
| 94 | + Log.Write("SlashCmd", $"Updating slash commands..."); |
90 | 95 | var moderatorCommands = new List<RestGuildCommand>(); |
91 | | - foreach (var command in module.CommandHandlers) |
| 96 | + foreach (var updateable in commandsToUpdate) |
92 | 97 | { |
93 | | - var guildCommand = await _client.Rest.CreateGuildCommand(command.Build(), Settings.Current.GuildID); |
| 98 | + await updateable.command.DeleteAsync(); |
| 99 | + |
| 100 | + var guildCommand = await _client.Rest.CreateGuildCommand(updateable.handler.Build(), Settings.Current.GuildID); |
94 | 101 | if (guildCommand.IsDefaultPermission == false) |
95 | 102 | moderatorCommands.Add(guildCommand); |
| 103 | + |
| 104 | + Log.Write("SlashCmd", $"Successfully updated slash command {updateable.handler.Name}."); |
96 | 105 | } |
97 | 106 |
|
98 | 107 | await ApplyCommandPermissions(_client, moderatorCommands); |
|
0 commit comments