From f5d064dfc389b831538e6bd51cdacdb40db84690 Mon Sep 17 00:00:00 2001 From: quin lynch Date: Sat, 21 Aug 2021 07:10:49 -0300 Subject: [PATCH] Add more routes to guilds and clients. --- src/Discord.Net.Core/Discord.Net.Core.xml | 40 ++++++++++++ .../Entities/Guilds/IGuild.cs | 21 +++++++ src/Discord.Net.Core/IDiscordClient.cs | 20 ++++++ src/Discord.Net.Rest/BaseDiscordClient.cs | 5 ++ src/Discord.Net.Rest/ClientHelper.cs | 27 ++++++++ src/Discord.Net.Rest/Discord.Net.Rest.xml | 29 +++++++++ src/Discord.Net.Rest/DiscordRestClient.cs | 12 ++-- .../Entities/Guilds/RestGuild.cs | 37 +++++++++++ .../Interactions/InteractionHelper.cs | 26 +++----- src/Discord.Net.WebSocket/ClientState.cs | 12 ++++ .../Discord.Net.WebSocket.csproj | 2 +- .../Discord.Net.WebSocket.xml | 32 ++++++++++ .../DiscordSocketClient.cs | 29 +++++++++ .../Entities/Guilds/SocketGuild.cs | 63 ++++++++++++++++++- 14 files changed, 328 insertions(+), 27 deletions(-) diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index 879e5613d..c8695e4f1 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -3936,6 +3936,26 @@ if found, otherwise . + + + Creates an application command within this guild. + + The properties to use when creating the command. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains the command that was created. + + + + + Overwrites the application commands within this guild. + + A collection of properties to use when creating the commands. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + + Holds information for a guild integration feature. @@ -11004,6 +11024,26 @@ application commands. + + + Creates a global application command. + + The properties to use when creating the command. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains the created application command. + + + + + Bulk overwrites all global application commands. + + A collection of properties to use when creating the commands. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. + + Gets a guild. diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index a94c1ed33..cd578e621 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -964,5 +964,26 @@ namespace Discord /// Task GetApplicationCommandAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null); + + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + Task> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/IDiscordClient.cs b/src/Discord.Net.Core/IDiscordClient.cs index a728e6096..f6981d552 100644 --- a/src/Discord.Net.Core/IDiscordClient.cs +++ b/src/Discord.Net.Core/IDiscordClient.cs @@ -162,6 +162,26 @@ namespace Discord /// Task> GetGlobalApplicationCommandsAsync(RequestOptions options = null); + /// + /// Creates a global application command. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created application command. + /// + Task CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null); + + /// + /// Bulk overwrites all global application commands. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. + /// + Task> BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, RequestOptions options = null); + /// /// Gets a guild. /// diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index c94723281..93b82c929 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -223,6 +223,11 @@ namespace Discord.Rest /// Task> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); + Task IDiscordClient.CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options) + => Task.FromResult(null); + Task> IDiscordClient.BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, + RequestOptions options) + => Task.FromResult>(ImmutableArray.Create()); /// Task IDiscordClient.StartAsync() diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 19c3b1325..2fc382900 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -229,7 +229,34 @@ namespace Discord.Rest return model != null ? RestGuildCommand.Create(client, model, guildId) : null; } + public static async Task CreateGuildApplicationCommand(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties, + RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommand(client, guildId, properties, options); + + return RestGuildCommand.Create(client, model, guildId); + } + public static async Task CreateGlobalApplicationCommand(BaseDiscordClient client, ApplicationCommandProperties properties, + RequestOptions options = null) + { + var model = await InteractionHelper.CreateGlobalCommand(client, properties, options); + + return RestGlobalCommand.Create(client, model); + } + public static async Task> BulkOverwriteGlobalApplicationCommand(BaseDiscordClient client, ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGlobalCommands(client, properties, options); + return models.Select(x => RestGlobalCommand.Create(client, x)).ToImmutableArray(); + } + public static async Task> BulkOverwriteGuildApplicationCommand(BaseDiscordClient client, ulong guildId, + ApplicationCommandProperties[] properties, RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommands(client, guildId, properties, options); + + return models.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); + } public static Task AddRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) => client.ApiClient.AddRoleAsync(guildId, userId, roleId, options); diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.xml b/src/Discord.Net.Rest/Discord.Net.Rest.xml index 2167ad1c5..02065499d 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.xml +++ b/src/Discord.Net.Rest/Discord.Net.Rest.xml @@ -3526,6 +3526,26 @@ if found, otherwise . + + + Creates an application command within this guild. + + The properties to use when creating the command. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains the command that was created. + + + + + Overwrites the application commands within this guild. + + A collection of properties to use when creating the commands. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + + Returns the name of the guild. @@ -3686,6 +3706,15 @@ + + + + + + + + + diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index feef4c12a..10a4c40a9 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -109,21 +109,17 @@ namespace Discord.Rest => ClientHelper.GetWebhookAsync(this, id, options); public Task CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null) - => InteractionHelper.CreateGlobalCommand(this, properties, options); - public Task CreateGlobalCommand(Action func, RequestOptions options = null) - => InteractionHelper.CreateGlobalCommand(this, func, options); + => ClientHelper.CreateGlobalApplicationCommand(this, properties, options); public Task CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null) - => InteractionHelper.CreateGuildCommand(this, guildId, properties, options); - public Task CreateGuildCommand(Action func, ulong guildId, RequestOptions options = null) - => InteractionHelper.CreateGuildCommand(this, guildId, func, options); + => ClientHelper.CreateGuildApplicationCommand(this, guildId, properties, options); public Task> GetGlobalApplicationCommands(RequestOptions options = null) => ClientHelper.GetGlobalApplicationCommands(this, options); public Task> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) => ClientHelper.GetGuildApplicationCommands(this, guildId, options); public Task> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null) - => InteractionHelper.BulkOverwriteGlobalCommands(this, commandProperties, options); + => ClientHelper.BulkOverwriteGlobalApplicationCommand(this, commandProperties, options); public Task> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null) - => InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options); + => ClientHelper.BulkOverwriteGuildApplicationCommand(this, guildId, commandProperties, options); public Task> BatchEditGuildCommandPermissions(ulong guildId, IDictionary permissions, RequestOptions options = null) => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index bf4365a5f..1c453910d 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -891,6 +891,35 @@ namespace Discord.Rest /// public async Task GetApplicationCommandAsync(ulong id, RequestOptions options = null) => await ClientHelper.GetGuildApplicationCommand(Discord, id, this.Id, options); + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommand(Discord, this.Id, properties, options); + + return RestGuildCommand.Create(Discord, model, this.Id); + } + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + public async Task> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommands(Discord, this.Id, properties, options); + + return models.Select(x => RestGuildCommand.Create(Discord, x, this.Id)).ToImmutableArray(); + } /// /// Returns the name of the guild. @@ -1180,6 +1209,14 @@ namespace Discord.Rest /// async Task> IGuild.GetApplicationCommandsAsync (RequestOptions options) => await GetApplicationCommandsAsync(options).ConfigureAwait(false); + /// + async Task IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) + => await CreateApplicationCommandAsync(properties, options); + /// + async Task> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options) + => await BulkOverwriteApplicationCommandsAsync(properties, options); + /// async Task IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index adf6226e2..59d5c4f2b 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -52,14 +52,14 @@ namespace Discord.Rest return RestGlobalCommand.Create(client, model); } - public static Task CreateGlobalCommand(BaseDiscordClient client, + public static Task CreateGlobalCommand(BaseDiscordClient client, Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties { var args = Activator.CreateInstance(typeof(TArg)); func((TArg)args); return CreateGlobalCommand(client, (TArg)args, options); } - public static async Task CreateGlobalCommand(BaseDiscordClient client, + public static async Task CreateGlobalCommand(BaseDiscordClient client, ApplicationCommandProperties arg, RequestOptions options = null) { Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); @@ -85,11 +85,10 @@ namespace Discord.Rest : Optional.Unspecified; } - var cmd = await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); - return RestGlobalCommand.Create(client, cmd); + return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); } - public static async Task> BulkOverwriteGlobalCommands(BaseDiscordClient client, + public static async Task BulkOverwriteGlobalCommands(BaseDiscordClient client, ApplicationCommandProperties[] args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); @@ -124,12 +123,10 @@ namespace Discord.Rest models.Add(model); } - var apiModels = await client.ApiClient.BulkOverwriteGlobalApplicationCommands(models.ToArray(), options).ConfigureAwait(false); - - return apiModels.Select(x => RestGlobalCommand.Create(client, x)).ToArray(); + return await client.ApiClient.BulkOverwriteGlobalApplicationCommands(models.ToArray(), options).ConfigureAwait(false); } - public static async Task> BulkOverwriteGuildCommands(BaseDiscordClient client, ulong guildId, + public static async Task> BulkOverwriteGuildCommands(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties[] args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); @@ -164,9 +161,7 @@ namespace Discord.Rest models.Add(model); } - var apiModels = await client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, models.ToArray(), options).ConfigureAwait(false); - - return apiModels.Select(x => RestGuildCommand.Create(client, x, guildId)).ToArray(); + return await client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, models.ToArray(), options).ConfigureAwait(false); } public static Task ModifyGlobalCommand(BaseDiscordClient client, IApplicationCommand command, @@ -229,7 +224,7 @@ namespace Discord.Rest } // Guild Commands - public static Task CreateGuildCommand(BaseDiscordClient client, ulong guildId, + public static Task CreateGuildCommand(BaseDiscordClient client, ulong guildId, Action func, RequestOptions options) where TArg : ApplicationCommandProperties { var args = Activator.CreateInstance(typeof(TArg)); @@ -237,7 +232,7 @@ namespace Discord.Rest return CreateGuildCommand(client, guildId, (TArg)args, options); } - public static async Task CreateGuildCommand(BaseDiscordClient client, ulong guildId, + public static async Task CreateGuildCommand(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties arg, RequestOptions options = null) { var model = new CreateApplicationCommandParams() @@ -261,8 +256,7 @@ namespace Discord.Rest : Optional.Unspecified; } - var cmd = await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); - return RestGuildCommand.Create(client, cmd, guildId); + return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); } public static Task ModifyGuildCommand(BaseDiscordClient client, IApplicationCommand command, ulong guildId, diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index 653eec4c8..7129feb48 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -39,6 +39,7 @@ namespace Discord.WebSocket _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); + _commands = new ConcurrentDictionary(); } internal SocketChannel GetChannel(ulong id) @@ -152,11 +153,22 @@ namespace Discord.WebSocket { _commands[command.Id] = command; } + internal SocketApplicationCommand GetOrAddCommand(ulong id, Func commandFactory) + { + return _commands.GetOrAdd(id, commandFactory); + } internal SocketApplicationCommand RemoveCommand(ulong id) { if (_commands.TryRemove(id, out SocketApplicationCommand command)) return command; return null; } + internal void PurgeCommands(Func precondition) + { + var ids = _commands.Where(x => precondition(x.Value)).Select(x => x.Key); + + foreach (var id in ids) + _commands.TryRemove(id, out var _); + } } } diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index 167ccebb0..e6352780e 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -20,7 +20,7 @@ 3.0.1 - TRACE; + TRACE diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index 1a7504102..1fb19d207 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -3290,6 +3290,38 @@ slash commands created by the current user. + + + Gets an application command within this guild with the specified id. + + The id of the application command to get. + The that determines whether the object should be fetched from cache. + The options to be used when sending the request. + + A ValueTask that represents the asynchronous get operation. The task result contains a + if found, otherwise . + + + + + Creates an application command within this guild. + + The properties to use when creating the command. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains the command that was created. + + + + + Overwrites the application commands within this guild. + + A collection of properties to use when creating the commands. + The options to be used when sending the request. + + A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + + Gets a collection of all invites in this guild. diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 53d712dbf..2f99e60d3 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -391,6 +391,35 @@ namespace Discord.WebSocket return commands.ToImmutableArray(); } + public async Task CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGlobalCommand(this, properties, options).ConfigureAwait(false); + + var entity = State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(this, model)); + + // update it incase it was cached + entity.Update(model); + + return entity; + } + public async Task> BulkOverwriteGlobalApplicationCommandsAsync( + ApplicationCommandProperties[] properties, RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGlobalCommands(this, properties, options); + + var entities = models.Select(x => SocketApplicationCommand.Create(this, x)); + + // purge our previous commands + State.PurgeCommands(x => x.IsGlobalCommand); + + foreach(var entity in entities) + { + State.AddCommand(entity); + } + + return entities.ToImmutableArray(); + } + /// /// Clears cached users from the client. /// diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 3b92e6a22..19af8038f 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -804,7 +804,7 @@ namespace Discord.WebSocket /// public async Task> GetApplicationCommandsAsync(RequestOptions options = null) { - var commands = (await Discord.ApiClient.GetGuildApplicationCommandsAsync(this.Id, options)).Select(x => SocketApplicationCommand.Create(Discord, x)); + var commands = (await Discord.ApiClient.GetGuildApplicationCommandsAsync(this.Id, options)).Select(x => SocketApplicationCommand.Create(Discord, x, this.Id)); foreach (var command in commands) { @@ -814,6 +814,16 @@ namespace Discord.WebSocket return commands.ToImmutableArray(); } + /// + /// Gets an application command within this guild with the specified id. + /// + /// The id of the application command to get. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A ValueTask that represents the asynchronous get operation. The task result contains a + /// if found, otherwise . + /// public async ValueTask GetApplicationCommandAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) { var command = Discord.State.GetCommand(id); @@ -829,13 +839,57 @@ namespace Discord.WebSocket if (model == null) return null; - command = SocketApplicationCommand.Create(Discord, model); + command = SocketApplicationCommand.Create(Discord, model, this.Id); Discord.State.AddCommand(command); return command; } + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommand(Discord, this.Id, properties, options); + + var entity = Discord.State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(Discord, model)); + + entity.Update(model); + + return entity; + } + + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + public async Task> BulkOverwriteApplicationCommandAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommands(Discord, this.Id, properties, options); + + var entities = models.Select(x => SocketApplicationCommand.Create(Discord, x)); + + Discord.State.PurgeCommands(x => !x.IsGlobalCommand && x.Guild.Id == this.Id); + + foreach(var entity in entities) + { + Discord.State.AddCommand(entity); + } + + return entities.ToImmutableArray(); + } + //Invites /// /// Gets a collection of all invites in this guild. @@ -1490,6 +1544,11 @@ namespace Discord.WebSocket => await GetApplicationCommandsAsync(options).ConfigureAwait(false); async Task IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) => await GetApplicationCommandAsync(id, mode, options); + async Task IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) + => await CreateApplicationCommandAsync(properties, options); + async Task> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options) + => await BulkOverwriteApplicationCommandAsync(properties, options); void IDisposable.Dispose() {