| @@ -3936,6 +3936,26 @@ | |||
| if found, otherwise <see langword="null"/>. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.IGuild.CreateApplicationCommandAsync(Discord.ApplicationCommandProperties,Discord.RequestOptions)"> | |||
| <summary> | |||
| Creates an application command within this guild. | |||
| </summary> | |||
| <param name="properties">The properties to use when creating the command.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.IGuild.BulkOverwriteApplicationCommandsAsync(Discord.ApplicationCommandProperties[],Discord.RequestOptions)"> | |||
| <summary> | |||
| Overwrites the application commands within this guild. | |||
| </summary> | |||
| <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="T:Discord.IGuildIntegration"> | |||
| <summary> | |||
| Holds information for a guild integration feature. | |||
| @@ -11004,6 +11024,26 @@ | |||
| application commands. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.IDiscordClient.CreateGlobalApplicationCommand(Discord.ApplicationCommandProperties,Discord.RequestOptions)"> | |||
| <summary> | |||
| Creates a global application command. | |||
| </summary> | |||
| <param name="properties">The properties to use when creating the command.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains the created application command. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.IDiscordClient.BulkOverwriteGlobalApplicationCommand(Discord.ApplicationCommandProperties[],Discord.RequestOptions)"> | |||
| <summary> | |||
| Bulk overwrites all global application commands. | |||
| </summary> | |||
| <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.IDiscordClient.GetGuildAsync(System.UInt64,Discord.CacheMode,Discord.RequestOptions)"> | |||
| <summary> | |||
| Gets a guild. | |||
| @@ -964,5 +964,26 @@ namespace Discord | |||
| /// </returns> | |||
| Task<IApplicationCommand> GetApplicationCommandAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, | |||
| RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates an application command within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">The properties to use when creating the command.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| /// </returns> | |||
| Task<IApplicationCommand> CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Overwrites the application commands within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, | |||
| RequestOptions options = null); | |||
| } | |||
| } | |||
| @@ -162,6 +162,26 @@ namespace Discord | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IApplicationCommand>> GetGlobalApplicationCommandsAsync(RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates a global application command. | |||
| /// </summary> | |||
| /// <param name="properties">The properties to use when creating the command.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains the created application command. | |||
| /// </returns> | |||
| Task<IApplicationCommand> CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Bulk overwrites all global application commands. | |||
| /// </summary> | |||
| /// <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Gets a guild. | |||
| /// </summary> | |||
| @@ -223,6 +223,11 @@ namespace Discord.Rest | |||
| /// <inheritdoc /> | |||
| Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IApplicationCommand>>(ImmutableArray.Create<IApplicationCommand>()); | |||
| Task<IApplicationCommand> IDiscordClient.CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options) | |||
| => Task.FromResult<IApplicationCommand>(null); | |||
| Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, | |||
| RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IApplicationCommand>>(ImmutableArray.Create<IApplicationCommand>()); | |||
| /// <inheritdoc /> | |||
| Task IDiscordClient.StartAsync() | |||
| @@ -229,7 +229,34 @@ namespace Discord.Rest | |||
| return model != null ? RestGuildCommand.Create(client, model, guildId) : null; | |||
| } | |||
| public static async Task<RestGuildCommand> 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<RestGlobalCommand> 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<IReadOnlyCollection<RestGlobalCommand>> 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<IReadOnlyCollection<RestGuildCommand>> 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); | |||
| @@ -3526,6 +3526,26 @@ | |||
| if found, otherwise <see langword="null"/>. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.CreateApplicationCommandAsync(Discord.ApplicationCommandProperties,Discord.RequestOptions)"> | |||
| <summary> | |||
| Creates an application command within this guild. | |||
| </summary> | |||
| <param name="properties">The properties to use when creating the command.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.BulkOverwriteApplicationCommandsAsync(Discord.ApplicationCommandProperties[],Discord.RequestOptions)"> | |||
| <summary> | |||
| Overwrites the application commands within this guild. | |||
| </summary> | |||
| <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.ToString"> | |||
| <summary> | |||
| Returns the name of the guild. | |||
| @@ -3686,6 +3706,15 @@ | |||
| <member name="M:Discord.Rest.RestGuild.Discord#IGuild#GetApplicationCommandsAsync(Discord.RequestOptions)"> | |||
| <inheritdoc /> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.Discord#IGuild#CreateApplicationCommandAsync(Discord.ApplicationCommandProperties,Discord.RequestOptions)"> | |||
| <inheritdoc /> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.Discord#IGuild#BulkOverwriteApplicationCommandsAsync(Discord.ApplicationCommandProperties[],Discord.RequestOptions)"> | |||
| <inheritdoc /> | |||
| </member> | |||
| <member name="M:Discord.Rest.RestGuild.Discord#IGuild#GetApplicationCommandAsync(System.UInt64,Discord.CacheMode,Discord.RequestOptions)"> | |||
| <inheritdoc /> | |||
| </member> | |||
| <member name="P:Discord.Rest.RestGuildIntegration.Name"> | |||
| <inheritdoc /> | |||
| </member> | |||
| @@ -109,21 +109,17 @@ namespace Discord.Rest | |||
| => ClientHelper.GetWebhookAsync(this, id, options); | |||
| public Task<RestGlobalCommand> CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null) | |||
| => InteractionHelper.CreateGlobalCommand(this, properties, options); | |||
| public Task<RestGlobalCommand> CreateGlobalCommand(Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||
| => InteractionHelper.CreateGlobalCommand(this, func, options); | |||
| => ClientHelper.CreateGlobalApplicationCommand(this, properties, options); | |||
| public Task<RestGuildCommand> CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null) | |||
| => InteractionHelper.CreateGuildCommand(this, guildId, properties, options); | |||
| public Task<RestGuildCommand> CreateGuildCommand(Action<ApplicationCommandProperties> func, ulong guildId, RequestOptions options = null) | |||
| => InteractionHelper.CreateGuildCommand(this, guildId, func, options); | |||
| => ClientHelper.CreateGuildApplicationCommand(this, guildId, properties, options); | |||
| public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(RequestOptions options = null) | |||
| => ClientHelper.GetGlobalApplicationCommands(this, options); | |||
| public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) | |||
| => ClientHelper.GetGuildApplicationCommands(this, guildId, options); | |||
| public Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null) | |||
| => InteractionHelper.BulkOverwriteGlobalCommands(this, commandProperties, options); | |||
| => ClientHelper.BulkOverwriteGlobalApplicationCommand(this, commandProperties, options); | |||
| public Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null) | |||
| => InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options); | |||
| => ClientHelper.BulkOverwriteGuildApplicationCommand(this, guildId, commandProperties, options); | |||
| public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null) | |||
| => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); | |||
| public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) | |||
| @@ -891,6 +891,35 @@ namespace Discord.Rest | |||
| /// </returns> | |||
| public async Task<RestGuildCommand> GetApplicationCommandAsync(ulong id, RequestOptions options = null) | |||
| => await ClientHelper.GetGuildApplicationCommand(Discord, id, this.Id, options); | |||
| /// <summary> | |||
| /// Creates an application command within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">The properties to use when creating the command.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| /// </returns> | |||
| public async Task<RestGuildCommand> CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) | |||
| { | |||
| var model = await InteractionHelper.CreateGuildCommand(Discord, this.Id, properties, options); | |||
| return RestGuildCommand.Create(Discord, model, this.Id); | |||
| } | |||
| /// <summary> | |||
| /// Overwrites the application commands within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| /// </returns> | |||
| public async Task<IReadOnlyCollection<RestGuildCommand>> 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(); | |||
| } | |||
| /// <summary> | |||
| /// Returns the name of the guild. | |||
| @@ -1180,6 +1209,14 @@ namespace Discord.Rest | |||
| /// <inheritdoc /> | |||
| async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync (RequestOptions options) | |||
| => await GetApplicationCommandsAsync(options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<IApplicationCommand> IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) | |||
| => await CreateApplicationCommandAsync(properties, options); | |||
| /// <inheritdoc /> | |||
| async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, | |||
| RequestOptions options) | |||
| => await BulkOverwriteApplicationCommandsAsync(properties, options); | |||
| /// <inheritdoc /> | |||
| async Task<IApplicationCommand> IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -52,14 +52,14 @@ namespace Discord.Rest | |||
| return RestGlobalCommand.Create(client, model); | |||
| } | |||
| public static Task<RestGlobalCommand> CreateGlobalCommand<TArg>(BaseDiscordClient client, | |||
| public static Task<ApplicationCommand> CreateGlobalCommand<TArg>(BaseDiscordClient client, | |||
| Action<TArg> 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<RestGlobalCommand> CreateGlobalCommand(BaseDiscordClient client, | |||
| public static async Task<ApplicationCommand> CreateGlobalCommand(BaseDiscordClient client, | |||
| ApplicationCommandProperties arg, RequestOptions options = null) | |||
| { | |||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||
| @@ -85,11 +85,10 @@ namespace Discord.Rest | |||
| : Optional<bool>.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<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalCommands(BaseDiscordClient client, | |||
| public static async Task<ApplicationCommand[]> 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<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildCommands(BaseDiscordClient client, ulong guildId, | |||
| public static async Task<IReadOnlyCollection<ApplicationCommand>> 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<ApplicationCommand> ModifyGlobalCommand<TArg>(BaseDiscordClient client, IApplicationCommand command, | |||
| @@ -229,7 +224,7 @@ namespace Discord.Rest | |||
| } | |||
| // Guild Commands | |||
| public static Task<RestGuildCommand> CreateGuildCommand<TArg>(BaseDiscordClient client, ulong guildId, | |||
| public static Task<ApplicationCommand> CreateGuildCommand<TArg>(BaseDiscordClient client, ulong guildId, | |||
| Action<TArg> 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<RestGuildCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, | |||
| public static async Task<ApplicationCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, | |||
| ApplicationCommandProperties arg, RequestOptions options = null) | |||
| { | |||
| var model = new CreateApplicationCommandParams() | |||
| @@ -261,8 +256,7 @@ namespace Discord.Rest | |||
| : Optional<bool>.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<ApplicationCommand> ModifyGuildCommand<TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId, | |||
| @@ -39,6 +39,7 @@ namespace Discord.WebSocket | |||
| _guilds = new ConcurrentDictionary<ulong, SocketGuild>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); | |||
| _users = new ConcurrentDictionary<ulong, SocketGlobalUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); | |||
| _groupChannels = new ConcurrentHashSet<ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); | |||
| _commands = new ConcurrentDictionary<ulong, SocketApplicationCommand>(); | |||
| } | |||
| internal SocketChannel GetChannel(ulong id) | |||
| @@ -152,11 +153,22 @@ namespace Discord.WebSocket | |||
| { | |||
| _commands[command.Id] = command; | |||
| } | |||
| internal SocketApplicationCommand GetOrAddCommand(ulong id, Func<ulong, SocketApplicationCommand> 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<SocketApplicationCommand, bool> precondition) | |||
| { | |||
| var ids = _commands.Where(x => precondition(x.Value)).Select(x => x.Key); | |||
| foreach (var id in ids) | |||
| _commands.TryRemove(id, out var _); | |||
| } | |||
| } | |||
| } | |||
| @@ -20,7 +20,7 @@ | |||
| <FileVersion>3.0.1</FileVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | |||
| <DefineConstants>TRACE;</DefineConstants> | |||
| <DefineConstants>TRACE</DefineConstants> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| @@ -3290,6 +3290,38 @@ | |||
| slash commands created by the current user. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.WebSocket.SocketGuild.GetApplicationCommandAsync(System.UInt64,Discord.CacheMode,Discord.RequestOptions)"> | |||
| <summary> | |||
| Gets an application command within this guild with the specified id. | |||
| </summary> | |||
| <param name="id">The id of the application command to get.</param> | |||
| <param name="mode">The <see cref="T:Discord.CacheMode" /> that determines whether the object should be fetched from cache.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A ValueTask that represents the asynchronous get operation. The task result contains a <see cref="T:Discord.IApplicationCommand"/> | |||
| if found, otherwise <see langword="null"/>. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.WebSocket.SocketGuild.CreateApplicationCommandAsync(Discord.ApplicationCommandProperties,Discord.RequestOptions)"> | |||
| <summary> | |||
| Creates an application command within this guild. | |||
| </summary> | |||
| <param name="properties">The properties to use when creating the command.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.WebSocket.SocketGuild.BulkOverwriteApplicationCommandAsync(Discord.ApplicationCommandProperties[],Discord.RequestOptions)"> | |||
| <summary> | |||
| Overwrites the application commands within this guild. | |||
| </summary> | |||
| <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| <param name="options">The options to be used when sending the request.</param> | |||
| <returns> | |||
| A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| </returns> | |||
| </member> | |||
| <member name="M:Discord.WebSocket.SocketGuild.GetInvitesAsync(Discord.RequestOptions)"> | |||
| <summary> | |||
| Gets a collection of all invites in this guild. | |||
| @@ -391,6 +391,35 @@ namespace Discord.WebSocket | |||
| return commands.ToImmutableArray(); | |||
| } | |||
| public async Task<SocketApplicationCommand> 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<IReadOnlyCollection<SocketApplicationCommand>> 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(); | |||
| } | |||
| /// <summary> | |||
| /// Clears cached users from the client. | |||
| /// </summary> | |||
| @@ -804,7 +804,7 @@ namespace Discord.WebSocket | |||
| /// </returns> | |||
| public async Task<IReadOnlyCollection<SocketApplicationCommand>> 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(); | |||
| } | |||
| /// <summary> | |||
| /// Gets an application command within this guild with the specified id. | |||
| /// </summary> | |||
| /// <param name="id">The id of the application command to get.</param> | |||
| /// <param name="mode">The <see cref="CacheMode" /> that determines whether the object should be fetched from cache.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A ValueTask that represents the asynchronous get operation. The task result contains a <see cref="IApplicationCommand"/> | |||
| /// if found, otherwise <see langword="null"/>. | |||
| /// </returns> | |||
| public async ValueTask<SocketApplicationCommand> 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; | |||
| } | |||
| /// <summary> | |||
| /// Creates an application command within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">The properties to use when creating the command.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains the command that was created. | |||
| /// </returns> | |||
| public async Task<SocketApplicationCommand> 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; | |||
| } | |||
| /// <summary> | |||
| /// Overwrites the application commands within this guild. | |||
| /// </summary> | |||
| /// <param name="properties">A collection of properties to use when creating the commands.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. | |||
| /// </returns> | |||
| public async Task<IReadOnlyCollection<SocketApplicationCommand>> 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 | |||
| /// <summary> | |||
| /// Gets a collection of all invites in this guild. | |||
| @@ -1490,6 +1544,11 @@ namespace Discord.WebSocket | |||
| => await GetApplicationCommandsAsync(options).ConfigureAwait(false); | |||
| async Task<IApplicationCommand> IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => await GetApplicationCommandAsync(id, mode, options); | |||
| async Task<IApplicationCommand> IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) | |||
| => await CreateApplicationCommandAsync(properties, options); | |||
| async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, | |||
| RequestOptions options) | |||
| => await BulkOverwriteApplicationCommandAsync(properties, options); | |||
| void IDisposable.Dispose() | |||
| { | |||