Browse Source

#2536 Add RemoveModulesFromGuildAsync (#2537)

* Add RemoveModulesFromGuildAsync

* fix RemoveModulesFromGuildAsync

* add docs

* fix parameter name
pull/2572/head
Gradyn Wursten GitHub 2 years ago
parent
commit
7acbcfdfa5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions
  1. +36
    -0
      src/Discord.Net.Interactions/InteractionService.cs

+ 36
- 0
src/Discord.Net.Interactions/InteractionService.cs View File

@@ -684,6 +684,42 @@ namespace Discord.Interactions
}
}

/// <summary>
/// Unregister Application Commands from modules provided in <paramref name="modules"/> from a guild.
/// </summary>
/// <param name="guild">The target guild.</param>
/// <param name="modules">Modules to be deregistered from Discord.</param>
/// <returns>
/// A task representing the command de-registration process. The task result contains the active application commands of the target guild.
/// </returns>
public async Task<IReadOnlyCollection<RestGuildCommand>> RemoveModulesFromGuildAsync(IGuild guild, params ModuleInfo[] modules)
{
if (guild is null)
throw new ArgumentNullException(nameof(guild));

return await RemoveModulesFromGuildAsync(guild.Id, modules).ConfigureAwait(false);
}

/// <summary>
/// Unregister Application Commands from modules provided in <paramref name="modules"/> from a guild.
/// </summary>
/// <param name="guildId">The target guild ID.</param>
/// <param name="modules">Modules to be deregistered from Discord.</param>
/// <returns>
/// A task representing the command de-registration process. The task result contains the active application commands of the target guild.
/// </returns>
public async Task<IReadOnlyCollection<RestGuildCommand>> 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))


Loading…
Cancel
Save