- Create `DeleteAllGlobalCommandsAsync` - Create `DeleteSlashCommandsAsync` Co-Authored-By: Quin Lynch <49576606+quinchs@users.noreply.github.com>pull/1923/head
@@ -2740,6 +2740,15 @@ | |||||
<member name="M:Discord.Rest.RestGuild.LeaveAsync(Discord.RequestOptions)"> | <member name="M:Discord.Rest.RestGuild.LeaveAsync(Discord.RequestOptions)"> | ||||
<inheritdoc /> | <inheritdoc /> | ||||
</member> | </member> | ||||
<member name="M:Discord.Rest.RestGuild.DeleteSlashCommandsAsync(Discord.RequestOptions)"> | |||||
<summary> | |||||
Deletes all slash commands in the current guild. | |||||
</summary> | |||||
<param name="options">The options to be used when sending the request.</param> | |||||
<returns> | |||||
A task that represents the asynchronous delete operation. | |||||
</returns> | |||||
</member> | |||||
<member name="M:Discord.Rest.RestGuild.GetSlashCommandsAsync(Discord.RequestOptions)"> | <member name="M:Discord.Rest.RestGuild.GetSlashCommandsAsync(Discord.RequestOptions)"> | ||||
<summary> | <summary> | ||||
Gets a collection of slash commands created by the current user in this guild. | Gets a collection of slash commands created by the current user in this guild. | ||||
@@ -125,7 +125,8 @@ namespace Discord.Rest | |||||
=> InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options); | => InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options); | ||||
public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null) | public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null) | ||||
=> InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); | => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); | ||||
public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) | |||||
=> InteractionHelper.DeleteAllGlobalCommandsAsync(this, options); | |||||
public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId) | public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId) | ||||
=> ClientHelper.AddRoleAsync(this, guildId, userId, roleId); | => ClientHelper.AddRoleAsync(this, guildId, userId, roleId); | ||||
@@ -256,6 +256,16 @@ namespace Discord.Rest | |||||
=> GuildHelper.LeaveAsync(this, Discord, options); | => GuildHelper.LeaveAsync(this, Discord, options); | ||||
//Interactions | //Interactions | ||||
/// <summary> | |||||
/// Deletes all slash commands in the current guild. | |||||
/// </summary> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous delete operation. | |||||
/// </returns> | |||||
public Task DeleteSlashCommandsAsync(RequestOptions options = null) | |||||
=> InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options); | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of slash commands created by the current user in this guild. | /// Gets a collection of slash commands created by the current user in this guild. | ||||
/// </summary> | /// </summary> | ||||
@@ -11,6 +11,16 @@ namespace Discord.Rest | |||||
{ | { | ||||
internal static class InteractionHelper | internal static class InteractionHelper | ||||
{ | { | ||||
public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) | |||||
{ | |||||
return client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, new CreateApplicationCommandParams[0], options); | |||||
} | |||||
public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null) | |||||
{ | |||||
return client.ApiClient.BulkOverwriteGlobalApplicationCommands(new CreateApplicationCommandParams[0], options); | |||||
} | |||||
public static Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response, | public static Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response, | ||||
ulong interactionId, string interactionToken, RequestOptions options = null) | ulong interactionId, string interactionToken, RequestOptions options = null) | ||||
{ | { | ||||
@@ -348,7 +358,7 @@ namespace Discord.Rest | |||||
return new GuildApplicationCommandPermission(model.Id, model.ApplicationId, guildId, model.Permissions.Select( | return new GuildApplicationCommandPermission(model.Id, model.ApplicationId, guildId, model.Permissions.Select( | ||||
y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray()); | y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray()); | ||||
} | } | ||||
catch(HttpException x) | |||||
catch (HttpException x) | |||||
{ | { | ||||
if (x.HttpCode == System.Net.HttpStatusCode.NotFound) | if (x.HttpCode == System.Net.HttpStatusCode.NotFound) | ||||
return null; | return null; | ||||
@@ -365,7 +375,7 @@ namespace Discord.Rest | |||||
List<ApplicationCommandPermissions> models = new List<ApplicationCommandPermissions>(); | List<ApplicationCommandPermissions> models = new List<ApplicationCommandPermissions>(); | ||||
foreach(var arg in args) | |||||
foreach (var arg in args) | |||||
{ | { | ||||
var model = new ApplicationCommandPermissions() | var model = new ApplicationCommandPermissions() | ||||
{ | { | ||||
@@ -391,7 +401,7 @@ namespace Discord.Rest | |||||
List<ModifyGuildApplicationCommandPermissions> models = new List<ModifyGuildApplicationCommandPermissions>(); | List<ModifyGuildApplicationCommandPermissions> models = new List<ModifyGuildApplicationCommandPermissions>(); | ||||
foreach(var arg in args) | |||||
foreach (var arg in args) | |||||
{ | { | ||||
Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); | Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); | ||||
@@ -2843,6 +2843,15 @@ | |||||
voice regions the guild can access. | voice regions the guild can access. | ||||
</returns> | </returns> | ||||
</member> | </member> | ||||
<member name="M:Discord.WebSocket.SocketGuild.DeleteSlashCommandsAsync(Discord.RequestOptions)"> | |||||
<summary> | |||||
Deletes all slash commands in the current guild. | |||||
</summary> | |||||
<param name="options">The options to be used when sending the request.</param> | |||||
<returns> | |||||
A task that represents the asynchronous delete operation. | |||||
</returns> | |||||
</member> | |||||
<member name="M:Discord.WebSocket.SocketGuild.GetSlashCommandsAsync(Discord.RequestOptions)"> | <member name="M:Discord.WebSocket.SocketGuild.GetSlashCommandsAsync(Discord.RequestOptions)"> | ||||
<summary> | <summary> | ||||
Gets a collection of slash commands created by the current user in this guild. | Gets a collection of slash commands created by the current user in this guild. | ||||
@@ -724,6 +724,16 @@ namespace Discord.WebSocket | |||||
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); | => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); | ||||
//Interactions | //Interactions | ||||
/// <summary> | |||||
/// Deletes all slash commands in the current guild. | |||||
/// </summary> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous delete operation. | |||||
/// </returns> | |||||
public Task DeleteSlashCommandsAsync(RequestOptions options = null) | |||||
=> InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options); | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of slash commands created by the current user in this guild. | /// Gets a collection of slash commands created by the current user in this guild. | ||||
/// </summary> | /// </summary> | ||||
@@ -823,7 +833,7 @@ namespace Discord.WebSocket | |||||
if (_roles.TryGetValue(model.Id, out SocketRole role)) | if (_roles.TryGetValue(model.Id, out SocketRole role)) | ||||
_roles[model.Id].Update(this.Discord.State, model); | _roles[model.Id].Update(this.Discord.State, model); | ||||
else | else | ||||
role = AddRole(model); | |||||
role = AddRole(model); | |||||
return role; | return role; | ||||
} | } | ||||
@@ -1289,7 +1299,7 @@ namespace Discord.WebSocket | |||||
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) | Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels); | => Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options) | |||||
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IReadOnlyCollection<ICategoryChannel>>(CategoryChannels); | => Task.FromResult<IReadOnlyCollection<ICategoryChannel>>(CategoryChannels); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) | ||||