diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index 035c6bed1..502860cd7 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -684,6 +684,42 @@ namespace Discord.Interactions } } + /// + /// Unregister Application Commands from modules provided in from a guild. + /// + /// The target guild. + /// Modules to be deregistered from Discord. + /// + /// A task representing the command de-registration process. The task result contains the active application commands of the target guild. + /// + public async Task> RemoveModulesFromGuildAsync(IGuild guild, params ModuleInfo[] modules) + { + if (guild is null) + throw new ArgumentNullException(nameof(guild)); + + return await RemoveModulesFromGuildAsync(guild.Id, modules).ConfigureAwait(false); + } + + /// + /// Unregister Application Commands from modules provided in from a guild. + /// + /// The target guild ID. + /// Modules to be deregistered from Discord. + /// + /// A task representing the command de-registration process. The task result contains the active application commands of the target guild. + /// + public async Task> RemoveModulesFromGuildAsync(ulong guildId, params ModuleInfo[] modules) + { + EnsureClientReady(); + + var exclude = modules.SelectMany(x => x.ToApplicationCommandProps(true)).ToList(); + var existing = await RestClient.GetGuildApplicationCommands(guildId).ConfigureAwait(false); + + var props = existing.Where(x => !exclude.Any(y => y.Name.IsSpecified && x.Name == y.Name.Value)).Select(x => x.ToApplicationCommandProps()); + + return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guildId).ConfigureAwait(false); + } + private bool RemoveModuleInternal (ModuleInfo moduleInfo) { if (!_moduleDefs.Remove(moduleInfo))