diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs index 6a8b3f69..5866b0f3 100644 --- a/src/Discord.Net.Commands/Info/CommandInfo.cs +++ b/src/Discord.Net.Commands/Info/CommandInfo.cs @@ -162,18 +162,18 @@ namespace Discord.Commands return PreconditionResult.FromSuccess(); } - public async Task ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null) + public Task ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null) { services ??= EmptyServiceProvider.Instance; if (!searchResult.IsSuccess) - return ParseResult.FromError(searchResult); + return Task.FromResult(ParseResult.FromError(searchResult)); if (preconditionResult != null && !preconditionResult.IsSuccess) - return ParseResult.FromError(preconditionResult); + return Task.FromResult(ParseResult.FromError(preconditionResult)); string input = searchResult.Text.Substring(startIndex); - return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap).ConfigureAwait(false); + return CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap); } public Task ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) diff --git a/src/Discord.Net.Commands/Info/ParameterInfo.cs b/src/Discord.Net.Commands/Info/ParameterInfo.cs index a6ba9dfd..85cb6419 100644 --- a/src/Discord.Net.Commands/Info/ParameterInfo.cs +++ b/src/Discord.Net.Commands/Info/ParameterInfo.cs @@ -87,10 +87,10 @@ namespace Discord.Commands return PreconditionResult.FromSuccess(); } - public async Task ParseAsync(ICommandContext context, string input, IServiceProvider services = null) + public Task ParseAsync(ICommandContext context, string input, IServiceProvider services = null) { services ??= EmptyServiceProvider.Instance; - return await _reader.ReadAsync(context, input, services).ConfigureAwait(false); + return _reader.ReadAsync(context, input, services); } public override string ToString() => Name; diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index 24c8a825..fded1486 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -42,12 +42,11 @@ namespace Discord.Commands /// A collection of stickers to send with the file. /// A array of s to send with this response. Max 10. /// Message flags combined as a bitfield. - protected virtual async Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, + protected virtual Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags).ConfigureAwait(false); - } + => Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); + /// /// The method to execute asynchronously before executing the command. /// diff --git a/src/Discord.Net.Commands/Readers/NullableTypeReader.cs b/src/Discord.Net.Commands/Readers/NullableTypeReader.cs index f68bf6e2..bae31503 100644 --- a/src/Discord.Net.Commands/Readers/NullableTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/NullableTypeReader.cs @@ -25,11 +25,11 @@ namespace Discord.Commands } /// - public override async Task ReadAsync(ICommandContext context, string input, IServiceProvider services) + public override Task ReadAsync(ICommandContext context, string input, IServiceProvider services) { if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase)) - return TypeReaderResult.FromSuccess(new T?()); - return await _baseTypeReader.ReadAsync(context, input, services).ConfigureAwait(false); + return Task.FromResult(TypeReaderResult.FromSuccess(new T?())); + return _baseTypeReader.ReadAsync(context, input, services); } } } diff --git a/src/Discord.Net.Core/Extensions/MessageExtensions.cs b/src/Discord.Net.Core/Extensions/MessageExtensions.cs index c2a2b649..0f8dbea5 100644 --- a/src/Discord.Net.Core/Extensions/MessageExtensions.cs +++ b/src/Discord.Net.Core/Extensions/MessageExtensions.cs @@ -94,9 +94,7 @@ namespace Discord /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - public static async Task ReplyAsync(this IUserMessage msg, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - return await msg.Channel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, new MessageReference(messageId: msg.Id), components, stickers, embeds, flags).ConfigureAwait(false); - } + public static Task ReplyAsync(this IUserMessage msg, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) + => msg.Channel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, new MessageReference(messageId: msg.Id), components, stickers, embeds, flags); } } diff --git a/src/Discord.Net.Core/Logging/LogManager.cs b/src/Discord.Net.Core/Logging/LogManager.cs index 42be8fb8..ecc8ec54 100644 --- a/src/Discord.Net.Core/Logging/LogManager.cs +++ b/src/Discord.Net.Core/Logging/LogManager.cs @@ -97,9 +97,7 @@ namespace Discord.Logging public Logger CreateLogger(string name) => new Logger(this, name); - public async Task WriteInitialLog() - { - await ClientLogger.InfoAsync($"Discord.Net v{DiscordConfig.Version} (API v{DiscordConfig.APIVersion})").ConfigureAwait(false); - } + public Task WriteInitialLog() + => ClientLogger.InfoAsync($"Discord.Net v{DiscordConfig.Version} (API v{DiscordConfig.APIVersion})"); } } diff --git a/src/Discord.Net.Core/Utils/Cacheable.cs b/src/Discord.Net.Core/Utils/Cacheable.cs index 99a76282..c0d3c300 100644 --- a/src/Discord.Net.Core/Utils/Cacheable.cs +++ b/src/Discord.Net.Core/Utils/Cacheable.cs @@ -47,10 +47,8 @@ namespace Discord /// A task that represents the asynchronous download operation. The task result contains the downloaded /// entity. /// - public async Task DownloadAsync() - { - return await DownloadFunc().ConfigureAwait(false); - } + public Task DownloadAsync() + => DownloadFunc(); /// /// Returns the cached entity if it exists; otherwise downloads it. @@ -103,9 +101,9 @@ namespace Discord /// A task that represents the asynchronous download operation. The task result contains the downloaded /// entity. /// - public async Task DownloadAsync() + public Task DownloadAsync() { - return await DownloadFunc().ConfigureAwait(false); + return DownloadFunc(); } /// diff --git a/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs index 1dd3cf2b..40ac54a0 100644 --- a/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs +++ b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs @@ -26,14 +26,14 @@ namespace Discord.Interactions } /// - public async Task ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + public Task ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services) { switch (InteractionService._runMode) { case RunMode.Sync: { - return await ExecuteInternalAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false); + return ExecuteInternalAsync(context, autocompleteInteraction, parameter, services); } case RunMode.Async: _ = Task.Run(async () => @@ -45,7 +45,7 @@ namespace Discord.Interactions throw new InvalidOperationException($"RunMode {InteractionService._runMode} is not supported."); } - return ExecuteResult.FromSuccess(); + return Task.FromResult((IResult)ExecuteResult.FromSuccess()); } private async Task ExecuteInternalAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, diff --git a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs index 6a6b3d66..377d6730 100644 --- a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs +++ b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs @@ -13,13 +13,13 @@ namespace Discord.Interactions /// Delegate that can be used to modify the modal. /// The request options for this request. /// A task that represents the asynchronous operation of responding to the interaction. - public static async Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, RequestOptions options = null, Action modifyModal = null) + public static Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, RequestOptions options = null, Action modifyModal = null) where T : class, IModal { if (!ModalUtils.TryGet(out var modalInfo)) throw new ArgumentException($"{typeof(T).FullName} isn't referenced by any registered Modal Interaction Command and doesn't have a cached {typeof(ModalInfo)}"); - await SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal); + return SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal); } /// @@ -35,13 +35,13 @@ namespace Discord.Interactions /// The request options for this request. /// Delegate that can be used to modify the modal. /// - public static async Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, InteractionService interactionService, + public static Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, InteractionService interactionService, RequestOptions options = null, Action modifyModal = null) where T : class, IModal { var modalInfo = ModalUtils.GetOrAdd(interactionService); - await SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal); + return SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal); } /// @@ -54,7 +54,7 @@ namespace Discord.Interactions /// The request options for this request. /// Delegate that can be used to modify the modal. /// - public static async Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, T modal, RequestOptions options = null, + public static Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, T modal, RequestOptions options = null, Action modifyModal = null) where T : class, IModal { @@ -79,13 +79,13 @@ namespace Discord.Interactions if (modifyModal is not null) modifyModal(builder); - await interaction.RespondWithModalAsync(builder.Build(), options).ConfigureAwait(false); + return interaction.RespondWithModalAsync(builder.Build(), options); } - private static async Task SendModalResponseAsync(IDiscordInteraction interaction, string customId, ModalInfo modalInfo, RequestOptions options = null, Action modifyModal = null) + private static Task SendModalResponseAsync(IDiscordInteraction interaction, string customId, ModalInfo modalInfo, RequestOptions options = null, Action modifyModal = null) { var modal = modalInfo.ToModal(customId, modifyModal); - await interaction.RespondWithModalAsync(modal, options).ConfigureAwait(false); + return interaction.RespondWithModalAsync(modal, options); } } } diff --git a/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs index 1016e532..ae6c8b41 100644 --- a/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs @@ -36,12 +36,12 @@ namespace Discord.Interactions } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not IAutocompleteInteraction) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Autocomplete Interaction"); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Autocomplete Interaction")); - return await base.ExecuteAsync(context, services).ConfigureAwait(false); + return base.ExecuteAsync(context, services); } protected override Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs index 1545ba1a..06a4a712 100644 --- a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs @@ -88,12 +88,12 @@ namespace Discord.Interactions } /// - public virtual async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public virtual Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { switch (RunMode) { case RunMode.Sync: - return await ExecuteInternalAsync(context, services).ConfigureAwait(false); + return ExecuteInternalAsync(context, services); case RunMode.Async: _ = Task.Run(async () => { @@ -104,7 +104,7 @@ namespace Discord.Interactions throw new InvalidOperationException($"RunMode {RunMode} is not supported."); } - return ExecuteResult.FromSuccess(); + return Task.FromResult((IResult)ExecuteResult.FromSuccess()); } protected abstract Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services); diff --git a/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs index aac8e5fb..37a467c7 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs @@ -24,12 +24,12 @@ namespace Discord.Interactions } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not IComponentInteraction) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Component Interaction"); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Component Interaction")); - return await base.ExecuteAsync(context, services).ConfigureAwait(false); + return base.ExecuteAsync(context, services); } protected override async Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs index 76eda2cf..d545f7a4 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs @@ -12,12 +12,12 @@ namespace Discord.Interactions : base(builder, module, commandService) { } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not IMessageCommandInteraction) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation"); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation")); - return await base.ExecuteAsync(context, services).ConfigureAwait(false); + return base.ExecuteAsync(context, services); } protected override Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs index a26f3f56..9f28a5c1 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs @@ -12,12 +12,12 @@ namespace Discord.Interactions : base(builder, module, commandService) { } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not IUserCommandInteraction userCommand) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation"); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation")); - return await base.ExecuteAsync(context, services).ConfigureAwait(false); + return base.ExecuteAsync(context, services); } protected override Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs index 849b4de2..280d599b 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs @@ -28,12 +28,12 @@ namespace Discord.Interactions } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not IModalInteraction modalInteraction) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Modal Interaction."); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Modal Interaction.")); - return await base.ExecuteAsync(context, services).ConfigureAwait(false); + return base.ExecuteAsync(context, services); } protected override async Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs index 8cbf438e..02df9883 100644 --- a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs @@ -64,12 +64,12 @@ namespace Discord.Interactions } /// - public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + public override Task ExecuteAsync(IInteractionContext context, IServiceProvider services) { if (context.Interaction is not ISlashCommandInteraction) - return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Slash Command Interaction"); + return Task.FromResult((IResult)ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Slash Command Interaction")); - return await base.ExecuteAsync(context, services); + return base.ExecuteAsync(context, services); } protected override async Task ParseArgumentsAsync(IInteractionContext context, IServiceProvider services) diff --git a/src/Discord.Net.Interactions/InteractionModuleBase.cs b/src/Discord.Net.Interactions/InteractionModuleBase.cs index f3b9d11c..a5e56e98 100644 --- a/src/Discord.Net.Interactions/InteractionModuleBase.cs +++ b/src/Discord.Net.Interactions/InteractionModuleBase.cs @@ -41,13 +41,13 @@ namespace Discord.Interactions } /// - protected virtual async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) => - await Context.Interaction.DeferAsync(ephemeral, options).ConfigureAwait(false); + protected virtual Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + => Context.Interaction.DeferAsync(ephemeral, options); /// - protected virtual async Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, - AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) => - await Context.Interaction.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + protected virtual Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) + => Context.Interaction.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); /// protected virtual Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, @@ -70,9 +70,9 @@ namespace Discord.Interactions => Context.Interaction.RespondWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); /// - protected virtual async Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, - AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) => - await Context.Interaction.FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + protected virtual Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) + => Context.Interaction.FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); /// protected virtual Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, @@ -95,10 +95,10 @@ namespace Discord.Interactions => Context.Interaction.FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); /// - protected virtual async Task ReplyAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, + protected virtual Task ReplyAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, - Embed[] embeds = null, MessageFlags flags = MessageFlags.None) => - await Context.Channel.SendMessageAsync(text, false, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags).ConfigureAwait(false); + Embed[] embeds = null, MessageFlags flags = MessageFlags.None) + => Context.Channel.SendMessageAsync(text, false, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); /// protected virtual Task GetOriginalResponseAsync(RequestOptions options = null) @@ -116,16 +116,16 @@ namespace Discord.Interactions } /// - protected virtual async Task RespondWithModalAsync(Modal modal, RequestOptions options = null) - => await Context.Interaction.RespondWithModalAsync(modal, options); + protected virtual Task RespondWithModalAsync(Modal modal, RequestOptions options = null) + => Context.Interaction.RespondWithModalAsync(modal, options); /// - protected virtual async Task RespondWithModalAsync(string customId, TModal modal, RequestOptions options = null, Action modifyModal = null) where TModal : class, IModal - => await Context.Interaction.RespondWithModalAsync(customId, modal, options, modifyModal); + protected virtual Task RespondWithModalAsync(string customId, TModal modal, RequestOptions options = null, Action modifyModal = null) where TModal : class, IModal + => Context.Interaction.RespondWithModalAsync(customId, modal, options, modifyModal); /// - protected virtual async Task RespondWithModalAsync(string customId, RequestOptions options = null, Action modifyModal = null) where TModal : class, IModal - => await Context.Interaction.RespondWithModalAsync(customId, options, modifyModal); + protected virtual Task RespondWithModalAsync(string customId, RequestOptions options = null, Action modifyModal = null) where TModal : class, IModal + => Context.Interaction.RespondWithModalAsync(customId, options, modifyModal); /// protected virtual Task RespondWithPremiumRequiredAsync(RequestOptions options = null) diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index fd5747d6..c23e355e 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -437,12 +437,12 @@ namespace Discord.Interactions /// /// A task representing the command registration process. The task result contains the active application commands of the target guild. /// - public async Task> AddCommandsToGuildAsync(IGuild guild, bool deleteMissing = false, params ICommandInfo[] commands) + public Task> AddCommandsToGuildAsync(IGuild guild, bool deleteMissing = false, params ICommandInfo[] commands) { if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await AddCommandsToGuildAsync(guild.Id, deleteMissing, commands).ConfigureAwait(false); + return AddCommandsToGuildAsync(guild.Id, deleteMissing, commands); } /// @@ -498,12 +498,12 @@ namespace Discord.Interactions /// /// A task representing the command registration process. The task result contains the active application commands of the target guild. /// - public async Task> AddModulesToGuildAsync(IGuild guild, bool deleteMissing = false, params ModuleInfo[] modules) + public Task> AddModulesToGuildAsync(IGuild guild, bool deleteMissing = false, params ModuleInfo[] modules) { if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await AddModulesToGuildAsync(guild.Id, deleteMissing, modules).ConfigureAwait(false); + return AddModulesToGuildAsync(guild.Id, deleteMissing, modules); } /// @@ -692,12 +692,12 @@ namespace Discord.Interactions /// /// 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) + public Task> RemoveModulesFromGuildAsync(IGuild guild, params ModuleInfo[] modules) { if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await RemoveModulesFromGuildAsync(guild.Id, modules).ConfigureAwait(false); + return RemoveModulesFromGuildAsync(guild.Id, modules); } /// @@ -1164,7 +1164,7 @@ namespace Discord.Interactions /// /// The active command permissions after the modification. /// - public async Task ModifySlashCommandPermissionsAsync(ModuleInfo module, IGuild guild, + public Task ModifySlashCommandPermissionsAsync(ModuleInfo module, IGuild guild, params ApplicationCommandPermission[] permissions) { if (module is null) @@ -1173,7 +1173,7 @@ namespace Discord.Interactions if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await ModifySlashCommandPermissionsAsync(module, guild.Id, permissions).ConfigureAwait(false); + return ModifySlashCommandPermissionsAsync(module, guild.Id, permissions); } /// @@ -1212,7 +1212,7 @@ namespace Discord.Interactions /// /// The active command permissions after the modification. /// - public async Task ModifySlashCommandPermissionsAsync(SlashCommandInfo command, IGuild guild, + public Task ModifySlashCommandPermissionsAsync(SlashCommandInfo command, IGuild guild, params ApplicationCommandPermission[] permissions) { if (command is null) @@ -1221,7 +1221,7 @@ namespace Discord.Interactions if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await ModifyApplicationCommandPermissionsAsync(command, guild.Id, permissions).ConfigureAwait(false); + return ModifyApplicationCommandPermissionsAsync(command, guild.Id, permissions); } /// @@ -1233,8 +1233,9 @@ namespace Discord.Interactions /// /// The active command permissions after the modification. /// - public async Task ModifySlashCommandPermissionsAsync(SlashCommandInfo command, ulong guildId, - params ApplicationCommandPermission[] permissions) => await ModifyApplicationCommandPermissionsAsync(command, guildId, permissions).ConfigureAwait(false); + public Task ModifySlashCommandPermissionsAsync(SlashCommandInfo command, ulong guildId, + params ApplicationCommandPermission[] permissions) + => ModifyApplicationCommandPermissionsAsync(command, guildId, permissions); /// /// Modify the command permissions of the matching Discord Slash Command. @@ -1245,7 +1246,7 @@ namespace Discord.Interactions /// /// The active command permissions after the modification. /// - public async Task ModifyContextCommandPermissionsAsync(ContextCommandInfo command, IGuild guild, + public Task ModifyContextCommandPermissionsAsync(ContextCommandInfo command, IGuild guild, params ApplicationCommandPermission[] permissions) { if (command is null) @@ -1254,7 +1255,7 @@ namespace Discord.Interactions if (guild is null) throw new ArgumentNullException(nameof(guild)); - return await ModifyApplicationCommandPermissionsAsync(command, guild.Id, permissions).ConfigureAwait(false); + return ModifyApplicationCommandPermissionsAsync(command, guild.Id, permissions); } /// @@ -1266,8 +1267,9 @@ namespace Discord.Interactions /// /// The active command permissions after the modification. /// - public async Task ModifyContextCommandPermissionsAsync(ContextCommandInfo command, ulong guildId, - params ApplicationCommandPermission[] permissions) => await ModifyApplicationCommandPermissionsAsync(command, guildId, permissions).ConfigureAwait(false); + public Task ModifyContextCommandPermissionsAsync(ContextCommandInfo command, ulong guildId, + params ApplicationCommandPermission[] permissions) + => ModifyApplicationCommandPermissionsAsync(command, guildId, permissions); private async Task ModifyApplicationCommandPermissionsAsync(T command, ulong guildId, params ApplicationCommandPermission[] permissions) where T : class, IApplicationCommandInfo, ICommandInfo diff --git a/src/Discord.Net.Interactions/RestInteractionModuleBase.cs b/src/Discord.Net.Interactions/RestInteractionModuleBase.cs index bc97d5ed..26e527f6 100644 --- a/src/Discord.Net.Interactions/RestInteractionModuleBase.cs +++ b/src/Discord.Net.Interactions/RestInteractionModuleBase.cs @@ -25,8 +25,8 @@ namespace Discord.Interactions /// A Task representing the operation of creating the interaction response. /// /// Thrown if the interaction isn't a type of . - protected override async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) - => await HandleInteractionAsync(x => x.Defer(ephemeral, options)); + protected override Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + => HandleInteractionAsync(x => x.Defer(ephemeral, options)); /// /// Respond to a Rest based Discord Interaction using the delegate. @@ -43,8 +43,8 @@ namespace Discord.Interactions /// A Task representing the operation of creating the interaction response. /// /// Thrown if the interaction isn't a type of . - protected override async Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) - => await HandleInteractionAsync(x => x.Respond(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options)); + protected override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) + => HandleInteractionAsync(x => x.Respond(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options)); /// /// Responds to the interaction with a modal. @@ -55,8 +55,8 @@ namespace Discord.Interactions /// A Task representing the operation of creating the interaction response. /// /// Thrown if the interaction isn't a type of . - protected override async Task RespondWithModalAsync(Modal modal, RequestOptions options = null) - => await HandleInteractionAsync(x => x.RespondWithModal(modal, options)); + protected override Task RespondWithModalAsync(Modal modal, RequestOptions options = null) + => HandleInteractionAsync(x => x.RespondWithModal(modal, options)); /// /// Responds to the interaction with a modal. @@ -84,10 +84,10 @@ namespace Discord.Interactions /// A Task representing the operation of creating the interaction response. /// /// Thrown if the interaction isn't a type of . - protected override async Task RespondWithModalAsync(string customId, RequestOptions options = null, Action modifyModal = null) - => await HandleInteractionAsync(x => x.RespondWithModal(customId, options, modifyModal)); + protected override Task RespondWithModalAsync(string customId, RequestOptions options = null, Action modifyModal = null) + => HandleInteractionAsync(x => x.RespondWithModal(customId, options, modifyModal)); - private async Task HandleInteractionAsync(Func action) + private Task HandleInteractionAsync(Func action) { if (Context.Interaction is not RestInteraction restInteraction) throw new InvalidOperationException($"Interaction must be a type of {nameof(RestInteraction)} in order to execute this method."); @@ -95,9 +95,9 @@ namespace Discord.Interactions var payload = action(restInteraction); if (Context is IRestInteractionContext restContext && restContext.InteractionResponseCallback != null) - await restContext.InteractionResponseCallback.Invoke(payload).ConfigureAwait(false); + return restContext.InteractionResponseCallback.Invoke(payload); else - await InteractionService._restResponseCallback(Context, payload).ConfigureAwait(false); + return InteractionService._restResponseCallback(Context, payload); } } } diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 5c4ee019..7d0c7b48 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -25,7 +25,7 @@ namespace Discord.Rest return RestApplication.Create(client, model); } - public static async Task ModifyCurrentBotApplicationAsync(BaseDiscordClient client, Action func, RequestOptions options) + public static Task ModifyCurrentBotApplicationAsync(BaseDiscordClient client, Action func, RequestOptions options) { var args = new ModifyApplicationProperties(); func(args); @@ -40,7 +40,7 @@ namespace Discord.Rest if (args.Description.IsSpecified) Preconditions.AtMost(args.Description.Value.Length, DiscordConfig.MaxApplicationDescriptionLength, nameof(args.Description), $"An application description tag mus have length less or equal to {DiscordConfig.MaxApplicationDescriptionLength}"); - return await client.ApiClient.ModifyCurrentBotApplicationAsync(new() + return client.ApiClient.ModifyCurrentBotApplicationAsync(new() { Description = args.Description, Tags = args.Tags, diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index d07d63c1..4f9d644d 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -203,7 +203,7 @@ namespace Discord.API internal Task SendAsync(string method, Expression> endpointExpr, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); - public async Task SendAsync(string method, string endpoint, + public Task SendAsync(string method, string endpoint, BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { options ??= new RequestOptions(); @@ -211,13 +211,13 @@ namespace Discord.API options.BucketId = bucketId; var request = new RestRequest(RestClient, method, endpoint, options); - await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); + return SendInternalAsync(method, endpoint, request); } internal Task SendJsonAsync(string method, Expression> endpointExpr, object payload, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) => SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); - public async Task SendJsonAsync(string method, string endpoint, object payload, + public Task SendJsonAsync(string method, string endpoint, object payload, BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { options ??= new RequestOptions(); @@ -226,13 +226,13 @@ namespace Discord.API string json = payload != null ? SerializeJson(payload) : null; var request = new JsonRestRequest(RestClient, method, endpoint, json, options); - await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); + return SendInternalAsync(method, endpoint, request); } internal Task SendMultipartAsync(string method, Expression> endpointExpr, IReadOnlyDictionary multipartArgs, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); - public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, + public Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { options ??= new RequestOptions(); @@ -240,7 +240,7 @@ namespace Discord.API options.BucketId = bucketId; var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options); - await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); + return SendInternalAsync(method, endpoint, request); } internal Task SendAsync(string method, Expression> endpointExpr, BucketIds ids, @@ -305,23 +305,23 @@ namespace Discord.API #endregion #region Auth - public async Task ValidateTokenAsync(RequestOptions options = null) + public Task ValidateTokenAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendAsync("GET", () => "auth/login", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "auth/login", new BucketIds(), options: options); } #endregion #region Gateway - public async Task GetGatewayAsync(RequestOptions options = null) + public Task GetGatewayAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => "gateway", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "gateway", new BucketIds(), options: options); } - public async Task GetBotGatewayAsync(RequestOptions options = null) + public Task GetBotGatewayAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => "gateway/bot", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "gateway/bot", new BucketIds(), options: options); } #endregion @@ -355,15 +355,15 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetGuildChannelsAsync(ulong guildId, RequestOptions options = null) + public Task> GetGuildChannelsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/channels", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/channels", ids, options: options); } - public async Task CreateGuildChannelAsync(ulong guildId, CreateGuildChannelParams args, RequestOptions options = null) + public Task CreateGuildChannelAsync(ulong guildId, CreateGuildChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -376,16 +376,16 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("POST", () => $"guilds/{guildId}/channels", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"guilds/{guildId}/channels", args, ids, options: options); } - public async Task DeleteChannelAsync(ulong channelId, RequestOptions options = null) + public Task DeleteChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendAsync("DELETE", () => $"channels/{channelId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}", ids, options: options); } /// /// must not be equal to zero. @@ -397,7 +397,7 @@ namespace Discord.API /// -and- /// must not be or empty. /// - public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyGuildChannelParams args, RequestOptions options = null) + public Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyGuildChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -410,7 +410,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options); } public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyTextChannelParams args, RequestOptions options = null) @@ -433,7 +433,7 @@ namespace Discord.API return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } - public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyVoiceChannelParams args, RequestOptions options = null) + public Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyVoiceChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -444,10 +444,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options); } - public async Task ModifyGuildChannelsAsync(ulong guildId, IEnumerable args, RequestOptions options = null) + public Task ModifyGuildChannelsAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -457,14 +457,12 @@ namespace Discord.API switch (channels.Length) { case 0: - return; + return Task.CompletedTask; case 1: - await ModifyGuildChannelAsync(channels[0].Id, new Rest.ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false); - break; + return ModifyGuildChannelAsync(channels[0].Id, new Rest.ModifyGuildChannelParams { Position = channels[0].Position }); default: var ids = new BucketIds(guildId: guildId); - await SendJsonAsync("PATCH", () => $"guilds/{guildId}/channels", channels, ids, options: options).ConfigureAwait(false); - break; + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/channels", channels, ids, options: options); } } @@ -481,34 +479,34 @@ namespace Discord.API #endregion #region Threads - public async Task CreatePostAsync(ulong channelId, CreatePostParams args, RequestOptions options = null) + public Task CreatePostAsync(ulong channelId, CreatePostParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); var bucket = new BucketIds(channelId: channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/threads", args, bucket, options: options); + return SendJsonAsync("POST", () => $"channels/{channelId}/threads", args, bucket, options: options); } - public async Task CreatePostAsync(ulong channelId, CreateMultipartPostAsync args, RequestOptions options = null) + public Task CreatePostAsync(ulong channelId, CreateMultipartPostAsync args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); var bucket = new BucketIds(channelId: channelId); - return await SendMultipartAsync("POST", () => $"channels/{channelId}/threads", args.ToDictionary(), bucket, options: options); + return SendMultipartAsync("POST", () => $"channels/{channelId}/threads", args.ToDictionary(), bucket, options: options); } - public async Task ModifyThreadAsync(ulong channelId, ModifyThreadParams args, RequestOptions options = null) + public Task ModifyThreadAsync(ulong channelId, ModifyThreadParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); var bucket = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, bucket, options: options); + return SendJsonAsync("PATCH", () => $"channels/{channelId}", args, bucket, options: options); } - public async Task StartThreadAsync(ulong channelId, ulong messageId, StartThreadParams args, RequestOptions options = null) + public Task StartThreadAsync(ulong channelId, ulong messageId, StartThreadParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -517,10 +515,10 @@ namespace Discord.API var bucket = new BucketIds(0, channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/threads", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/threads", args, bucket, options: options); } - public async Task StartThreadAsync(ulong channelId, StartThreadParams args, RequestOptions options = null) + public Task StartThreadAsync(ulong channelId, StartThreadParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -528,10 +526,10 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/threads", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{channelId}/threads", args, bucket, options: options); } - public async Task JoinThreadAsync(ulong channelId, RequestOptions options = null) + public Task JoinThreadAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -539,10 +537,10 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/thread-members/@me", bucket, options: options).ConfigureAwait(false); + return SendAsync("PUT", () => $"channels/{channelId}/thread-members/@me", bucket, options: options); } - public async Task AddThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + public Task AddThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(userId, 0, nameof(channelId)); @@ -551,10 +549,10 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); + return SendAsync("PUT", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options); } - public async Task LeaveThreadAsync(ulong channelId, RequestOptions options = null) + public Task LeaveThreadAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -562,10 +560,10 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/thread-members/@me", bucket, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/thread-members/@me", bucket, options: options); } - public async Task RemoveThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + public Task RemoveThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(userId, 0, nameof(channelId)); @@ -573,7 +571,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options); } public async Task ListThreadMembersAsync(ulong channelId, ulong? after = null, int? limit = null, RequestOptions options = null) @@ -594,7 +592,7 @@ namespace Discord.API return await SendAsync("GET", () => $"channels/{channelId}/thread-members{query}", bucket, options: options).ConfigureAwait(false); } - public async Task GetThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + public Task GetThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -604,10 +602,10 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); var query = "?with_member=true"; - return await SendAsync("GET", () => $"channels/{channelId}/thread-members/{userId}{query}", bucket, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"channels/{channelId}/thread-members/{userId}{query}", bucket, options: options); } - public async Task GetActiveThreadsAsync(ulong guildId, RequestOptions options = null) + public Task GetActiveThreadsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -615,10 +613,10 @@ namespace Discord.API var bucket = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options); + return SendAsync("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options); } - public async Task GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) + public Task GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -639,10 +637,10 @@ namespace Discord.API query = $"?before={beforeEncoded}"; } - return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/public{query}", bucket, options: options); + return SendAsync("GET", () => $"channels/{channelId}/threads/archived/public{query}", bucket, options: options); } - public async Task GetPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + public Task GetPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -664,10 +662,10 @@ namespace Discord.API query = $"?before={beforeEncoded}"; } - return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/private{query}", bucket, options: options); + return SendAsync("GET", () => $"channels/{channelId}/threads/archived/private{query}", bucket, options: options); } - public async Task GetJoinedPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + public Task GetJoinedPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -687,21 +685,21 @@ namespace Discord.API query = $"?before={before.Value.ToString("O")}"; } - return await SendAsync("GET", () => $"channels/{channelId}/users/@me/threads/archived/private{query}", bucket, options: options); + return SendAsync("GET", () => $"channels/{channelId}/users/@me/threads/archived/private{query}", bucket, options: options); } #endregion #region Stage - public async Task CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) + public Task CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(); - return await SendJsonAsync("POST", () => $"stage-instances", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"stage-instances", args, bucket, options: options); } - public async Task ModifyStageInstanceAsync(ulong channelId, ModifyStageInstanceParams args, RequestOptions options = null) + public Task ModifyStageInstanceAsync(ulong channelId, ModifyStageInstanceParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -709,7 +707,7 @@ namespace Discord.API var bucket = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"stage-instances/{channelId}", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"stage-instances/{channelId}", args, bucket, options: options); } public async Task DeleteStageInstanceAsync(ulong channelId, RequestOptions options = null) @@ -745,7 +743,7 @@ namespace Discord.API } } - public async Task ModifyMyVoiceState(ulong guildId, ModifyVoiceStateParams args, RequestOptions options = null) + public Task ModifyMyVoiceState(ulong guildId, ModifyVoiceStateParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -753,10 +751,10 @@ namespace Discord.API var bucket = new BucketIds(); - await SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/@me", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/@me", args, bucket, options: options); } - public async Task ModifyUserVoiceState(ulong guildId, ulong userId, ModifyVoiceStateParams args, RequestOptions options = null) + public Task ModifyUserVoiceState(ulong guildId, ulong userId, ModifyVoiceStateParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -765,12 +763,12 @@ namespace Discord.API var bucket = new BucketIds(); - await SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/{userId}", args, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/{userId}", args, bucket, options: options); } #endregion #region Roles - public async Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) + public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -779,9 +777,9 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); + return SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options); } - public async Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) + public Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -790,7 +788,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options); } #endregion @@ -808,7 +806,7 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetChannelMessagesAsync(ulong channelId, GetChannelMessagesParams args, RequestOptions options = null) + public Task> GetChannelMessagesAsync(ulong channelId, GetChannelMessagesParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -830,11 +828,12 @@ namespace Discord.API endpoint = () => $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}"; else endpoint = () => $"channels/{channelId}/messages?limit={limit}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + + return SendAsync>("GET", endpoint, ids, options: options); } /// Message content is too long, length must be less or equal to . - public async Task CreateMessageAsync(ulong channelId, CreateMessageParams args, RequestOptions options = null) + public Task CreateMessageAsync(ulong channelId, CreateMessageParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -845,13 +844,12 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/messages", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{channelId}/messages", args, ids, clientBucket: ClientBucketType.SendEdit, options: options); } - /// Message content is too long, length must be less or equal to . /// This operation may only be called with a token. - public async Task CreateWebhookMessageAsync(ulong webhookId, CreateWebhookMessageParams args, RequestOptions options = null, ulong? threadId = null) + public Task CreateWebhookMessageAsync(ulong webhookId, CreateWebhookMessageParams args, RequestOptions options = null, ulong? threadId = null) { if (AuthTokenType != TokenType.Webhook) throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); @@ -864,7 +862,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(webhookId: webhookId); - return await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options); } /// Message content is too long, length must be less or equal to . @@ -891,7 +889,7 @@ namespace Discord.API /// Message content is too long, length must be less or equal to . /// This operation may only be called with a token. - public async Task ModifyWebhookMessageAsync(ulong webhookId, ulong messageId, UploadWebhookFileParams args, RequestOptions options = null, ulong? threadId = null) + public Task ModifyWebhookMessageAsync(ulong webhookId, ulong messageId, UploadWebhookFileParams args, RequestOptions options = null, ulong? threadId = null) { if (AuthTokenType != TokenType.Webhook) throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); @@ -908,11 +906,11 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(webhookId: webhookId); - await SendMultipartAsync("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } /// This operation may only be called with a token. - public async Task DeleteWebhookMessageAsync(ulong webhookId, ulong messageId, RequestOptions options = null, ulong? threadId = null) + public Task DeleteWebhookMessageAsync(ulong webhookId, ulong messageId, RequestOptions options = null, ulong? threadId = null) { if (AuthTokenType != TokenType.Webhook) throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); @@ -923,11 +921,11 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(webhookId: webhookId); - await SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", ids, options: options); } /// Message content is too long, length must be less or equal to . - public async Task UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) + public Task UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -939,12 +937,12 @@ namespace Discord.API Preconditions.AtMost(args.Content.Value.Length, DiscordConfig.MaxMessageSize, nameof(args.Content), $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}."); var ids = new BucketIds(channelId: channelId); - return await SendMultipartAsync("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } /// Message content is too long, length must be less or equal to . /// This operation may only be called with a token. - public async Task UploadWebhookFileAsync(ulong webhookId, UploadWebhookFileParams args, RequestOptions options = null, ulong? threadId = null) + public Task UploadWebhookFileAsync(ulong webhookId, UploadWebhookFileParams args, RequestOptions options = null, ulong? threadId = null) { if (AuthTokenType != TokenType.Webhook) throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); @@ -959,20 +957,20 @@ namespace Discord.API Preconditions.AtMost(args.Content.Value.Length, DiscordConfig.MaxMessageSize, nameof(args.Content), $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}."); var ids = new BucketIds(webhookId: webhookId); - return await SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } - public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}", ids, options: options); } - public async Task DeleteMessagesAsync(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) + public Task DeleteMessagesAsync(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -984,18 +982,16 @@ namespace Discord.API switch (args.MessageIds.Length) { case 0: - return; + return Task.CompletedTask; case 1: - await DeleteMessageAsync(channelId, args.MessageIds[0]).ConfigureAwait(false); - break; + return DeleteMessageAsync(channelId, args.MessageIds[0]); default: var ids = new BucketIds(channelId: channelId); - await SendJsonAsync("POST", () => $"channels/{channelId}/messages/bulk-delete", args, ids, options: options).ConfigureAwait(false); - break; + return SendJsonAsync("POST", () => $"channels/{channelId}/messages/bulk-delete", args, ids, options: options); } } /// Message content is too long, length must be less or equal to . - public async Task ModifyMessageAsync(ulong channelId, ulong messageId, Rest.ModifyMessageParams args, RequestOptions options = null) + public Task ModifyMessageAsync(ulong channelId, ulong messageId, Rest.ModifyMessageParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1009,10 +1005,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options); } - public async Task ModifyMessageAsync(ulong channelId, ulong messageId, Rest.UploadFileParams args, RequestOptions options = null) + public Task ModifyMessageAsync(ulong channelId, ulong messageId, Rest.UploadFileParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1026,52 +1022,57 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendMultipartAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } #endregion #region Stickers, Reactions, Crosspost, and Acks - public async Task GetStickerAsync(ulong id, RequestOptions options = null) + public Task GetStickerAsync(ulong id, RequestOptions options = null) { Preconditions.NotEqual(id, 0, nameof(id)); options = RequestOptions.CreateOrClone(options); - return await NullifyNotFound(SendAsync("GET", () => $"stickers/{id}", new BucketIds(), options: options)).ConfigureAwait(false); + return NullifyNotFound(SendAsync("GET", () => $"stickers/{id}", new BucketIds(), options: options)); } - public async Task GetGuildStickerAsync(ulong guildId, ulong id, RequestOptions options = null) + + public Task GetGuildStickerAsync(ulong guildId, ulong id, RequestOptions options = null) { Preconditions.NotEqual(id, 0, nameof(id)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/stickers/{id}", new BucketIds(guildId), options: options)).ConfigureAwait(false); + return NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/stickers/{id}", new BucketIds(guildId), options: options)); } - public async Task ListGuildStickersAsync(ulong guildId, RequestOptions options = null) + + public Task ListGuildStickersAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"guilds/{guildId}/stickers", new BucketIds(guildId), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/stickers", new BucketIds(guildId), options: options); } - public async Task ListNitroStickerPacksAsync(RequestOptions options = null) + + public Task ListNitroStickerPacksAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"sticker-packs", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"sticker-packs", new BucketIds(), options: options); } - public async Task CreateGuildStickerAsync(CreateStickerParams args, ulong guildId, RequestOptions options = null) + + public Task CreateGuildStickerAsync(CreateStickerParams args, ulong guildId, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendMultipartAsync("POST", () => $"guilds/{guildId}/stickers", args.ToDictionary(), new BucketIds(guildId), options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"guilds/{guildId}/stickers", args.ToDictionary(), new BucketIds(guildId), options: options); } - public async Task ModifyStickerAsync(ModifyStickerParams args, ulong guildId, ulong stickerId, RequestOptions options = null) + + public Task ModifyStickerAsync(ModifyStickerParams args, ulong guildId, ulong stickerId, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1079,19 +1080,20 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/stickers/{stickerId}", args, new BucketIds(guildId), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/stickers/{stickerId}", args, new BucketIds(guildId), options: options); } - public async Task DeleteStickerAsync(ulong guildId, ulong stickerId, RequestOptions options = null) + + public Task DeleteStickerAsync(ulong guildId, ulong stickerId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(stickerId, 0, nameof(stickerId)); options = RequestOptions.CreateOrClone(options); - await SendAsync("DELETE", () => $"guilds/{guildId}/stickers/{stickerId}", new BucketIds(guildId), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/stickers/{stickerId}", new BucketIds(guildId), options: options); } - public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) + public Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1104,9 +1106,10 @@ namespace Discord.API // @me is non-const to fool the ratelimiter, otherwise it will put add/remove in separate buckets var me = "@me"; - await SendAsync("PUT", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{me}", ids, options: options).ConfigureAwait(false); + return SendAsync("PUT", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{me}", ids, options: options); } - public async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, string emoji, RequestOptions options = null) + + public Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, string emoji, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1118,9 +1121,10 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); var user = CurrentUserId.HasValue ? (userId == CurrentUserId.Value ? "@me" : userId.ToString()) : userId.ToString(); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{user}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{user}", ids, options: options); } - public async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null) + + public Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1129,9 +1133,10 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions", ids, options: options); } - public async Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) + + public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1141,10 +1146,10 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", ids, options: options); } - public async Task> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, ReactionType reactionType, RequestOptions options = null) + public Task> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, ReactionType reactionType, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -1160,49 +1165,51 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); Expression> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}&type={(int)reactionType}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", endpoint, ids, options: options); } - public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/ack", ids, options: options).ConfigureAwait(false); + return SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/ack", ids, options: options); } - public async Task TriggerTypingIndicatorAsync(ulong channelId, RequestOptions options = null) + + public Task TriggerTypingIndicatorAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options).ConfigureAwait(false); + return SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options); } - public async Task CrosspostAsync(ulong channelId, ulong messageId, RequestOptions options = null) + + public Task CrosspostAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options).ConfigureAwait(false); + return SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options); } - public async Task FollowChannelAsync(ulong newsChannelId, ulong followingChannelId, RequestOptions options = null) + public Task FollowChannelAsync(ulong newsChannelId, ulong followingChannelId, RequestOptions options = null) { Preconditions.NotEqual(newsChannelId, 0, nameof(newsChannelId)); Preconditions.NotEqual(followingChannelId, 0, nameof(followingChannelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: newsChannelId); - return await SendJsonAsync("POST", () => $"channels/{newsChannelId}/followers", new { webhook_channel_id = followingChannelId }, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{newsChannelId}/followers", new { webhook_channel_id = followingChannelId }, ids, options: options); } #endregion #region Channel Permissions - public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) + public Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(targetId, 0, nameof(targetId)); @@ -1210,73 +1217,75 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendJsonAsync("PUT", () => $"channels/{channelId}/permissions/{targetId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PUT", () => $"channels/{channelId}/permissions/{targetId}", args, ids, options: options); } - public async Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) + + public Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(targetId, 0, nameof(targetId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/permissions/{targetId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/permissions/{targetId}", ids, options: options); } #endregion #region Channel Pins - public async Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.GreaterThan(channelId, 0, nameof(channelId)); Preconditions.GreaterThan(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); - + return SendAsync("PUT", () => $"channels/{channelId}/pins/{messageId}", ids, options: options); } - public async Task RemovePinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + + public Task RemovePinAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/pins/{messageId}", ids, options: options); } - public async Task> GetPinsAsync(ulong channelId, RequestOptions options = null) + + public Task> GetPinsAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendAsync>("GET", () => $"channels/{channelId}/pins", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"channels/{channelId}/pins", ids, options: options); } #endregion #region Channel Recipients - public async Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + public Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.GreaterThan(channelId, 0, nameof(channelId)); Preconditions.GreaterThan(userId, 0, nameof(userId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); - + return SendAsync("PUT", () => $"channels/{channelId}/recipients/{userId}", ids, options: options); } - public async Task RemoveGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + + public Task RemoveGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(userId, 0, nameof(userId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"channels/{channelId}/recipients/{userId}", ids, options: options); } #endregion #region Interactions - public async Task GetGlobalApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null) + public Task GetGlobalApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1288,10 +1297,9 @@ namespace Discord.API options.RequestHeaders["X-Discord-Locale"] = new[] { locale }; } - //with_localizations=false doesnt return localized names and descriptions + //with_localizations=false doesn't return localized names and descriptions var query = withLocalizations ? "?with_localizations=true" : string.Empty; - return await SendAsync("GET", () => $"applications/{CurrentApplicationId}/commands{query}", - new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"applications/{CurrentApplicationId}/commands{query}", new BucketIds(), options: options); } public async Task GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null) @@ -1307,7 +1315,7 @@ namespace Discord.API catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task CreateGlobalApplicationCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) + public Task CreateGlobalApplicationCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) { Preconditions.NotNull(command, nameof(command)); Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); @@ -1322,41 +1330,45 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/commands", command, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/commands", command, new BucketIds(), options: options); } - public async Task ModifyGlobalApplicationCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + + public Task ModifyGlobalApplicationCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options); } - public async Task ModifyGlobalApplicationUserCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + + public Task ModifyGlobalApplicationUserCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options); } - public async Task ModifyGlobalApplicationMessageCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + + public Task ModifyGlobalApplicationMessageCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/commands/{commandId}", command, new BucketIds(), options: options); } - public async Task DeleteGlobalApplicationCommandAsync(ulong commandId, RequestOptions options = null) + + public Task DeleteGlobalApplicationCommandAsync(ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/commands/{commandId}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/commands/{commandId}", new BucketIds(), options: options); } - public async Task BulkOverwriteGlobalApplicationCommandsAsync(CreateApplicationCommandParams[] commands, RequestOptions options = null) + public Task BulkOverwriteGlobalApplicationCommandsAsync(CreateApplicationCommandParams[] commands, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/commands", commands, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/commands", commands, new BucketIds(), options: options); } - public async Task GetGuildApplicationCommandsAsync(ulong guildId, bool withLocalizations = false, string locale = null, RequestOptions options = null) + public Task GetGuildApplicationCommandsAsync(ulong guildId, bool withLocalizations = false, string locale = null, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1370,10 +1382,9 @@ namespace Discord.API options.RequestHeaders["X-Discord-Locale"] = new[] { locale }; } - //with_localizations=false doesnt return localized names and descriptions + //with_localizations=false doesn't return localized names and descriptions var query = withLocalizations ? "?with_localizations=true" : string.Empty; - return await SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands{query}", - bucket, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands{query}", bucket, options: options); } public async Task GetGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) @@ -1389,7 +1400,7 @@ namespace Discord.API catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task CreateGuildApplicationCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) + public Task CreateGuildApplicationCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) { Preconditions.NotNull(command, nameof(command)); Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); @@ -1406,46 +1417,49 @@ namespace Discord.API var bucket = new BucketIds(guildId: guildId); - return await SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands", command, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands", command, bucket, options: options); } - public async Task ModifyGuildApplicationCommandAsync(ModifyApplicationCommandParams command, ulong guildId, ulong commandId, RequestOptions options = null) + + public Task ModifyGuildApplicationCommandAsync(ModifyApplicationCommandParams command, ulong guildId, ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options); } - public async Task DeleteGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) + + public Task DeleteGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}", bucket, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}", bucket, options: options); } - public async Task BulkOverwriteGuildApplicationCommandsAsync(ulong guildId, CreateApplicationCommandParams[] commands, RequestOptions options = null) + public Task BulkOverwriteGuildApplicationCommandsAsync(ulong guildId, CreateApplicationCommandParams[] commands, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(guildId: guildId); - return await SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands", commands, bucket, options: options).ConfigureAwait(false); + return SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands", commands, bucket, options: options); } #endregion #region Interaction Responses - public async Task CreateInteractionResponseAsync(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) + public Task CreateInteractionResponseAsync(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) { if (response.Data.IsSpecified && response.Data.Value.Content.IsSpecified) Preconditions.AtMost(response.Data.Value.Content.Value?.Length ?? 0, 2000, nameof(response.Data.Value.Content)); options = RequestOptions.CreateOrClone(options); - await SendJsonAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response, new BucketIds(), options: options); + return SendJsonAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response, new BucketIds(), options: options); } - public async Task CreateInteractionResponseAsync(UploadInteractionFileParams response, ulong interactionId, string interactionToken, RequestOptions options = null) + + public Task CreateInteractionResponseAsync(UploadInteractionFileParams response, ulong interactionId, string interactionToken, RequestOptions options = null) { if ((!response.Embeds.IsSpecified || response.Embeds.Value == null || response.Embeds.Value.Length == 0) && !response.Files.Any()) Preconditions.NotNullOrEmpty(response.Content, nameof(response.Content)); @@ -1456,36 +1470,40 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(); - await SendMultipartAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } - public async Task GetInteractionResponseAsync(string interactionToken, RequestOptions options = null) + + public Task GetInteractionResponseAsync(string interactionToken, RequestOptions options = null) { Preconditions.NotNullOrEmpty(interactionToken, nameof(interactionToken)); options = RequestOptions.CreateOrClone(options); - return await NullifyNotFound(SendAsync("GET", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", new BucketIds(), options: options)).ConfigureAwait(false); + return NullifyNotFound(SendAsync("GET", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", new BucketIds(), options: options)); } - public async Task ModifyInteractionResponseAsync(ModifyInteractionResponseParams args, string interactionToken, RequestOptions options = null) + + public Task ModifyInteractionResponseAsync(ModifyInteractionResponseParams args, string interactionToken, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", args, new BucketIds(), options: options); + return SendJsonAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", args, new BucketIds(), options: options); } - public async Task ModifyInteractionResponseAsync(UploadWebhookFileParams args, string interactionToken, RequestOptions options = null) + + public Task ModifyInteractionResponseAsync(UploadWebhookFileParams args, string interactionToken, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendMultipartAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", args.ToDictionary(), new BucketIds(), options: options); + return SendMultipartAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", args.ToDictionary(), new BucketIds(), options: options); } - public async Task DeleteInteractionResponseAsync(string interactionToken, RequestOptions options = null) + + public Task DeleteInteractionResponseAsync(string interactionToken, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendAsync("DELETE", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", new BucketIds(), options: options); + return SendAsync("DELETE", () => $"webhooks/{CurrentApplicationId}/{interactionToken}/messages/@original", new BucketIds(), options: options); } - public async Task CreateInteractionFollowupMessageAsync(CreateWebhookMessageParams args, string token, RequestOptions options = null) + public Task CreateInteractionFollowupMessageAsync(CreateWebhookMessageParams args, string token, RequestOptions options = null) { if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) @@ -1504,12 +1522,12 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); if (!args.File.IsSpecified) - return await SendJsonAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args, new BucketIds(), options: options); else - return await SendMultipartAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args.ToDictionary(), new BucketIds(), options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args.ToDictionary(), new BucketIds(), options: options); } - public async Task CreateInteractionFollowupMessageAsync(UploadWebhookFileParams args, string token, RequestOptions options = null) + public Task CreateInteractionFollowupMessageAsync(UploadWebhookFileParams args, string token, RequestOptions options = null) { if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) @@ -1524,10 +1542,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(); - return await SendMultipartAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return SendMultipartAsync("POST", () => $"webhooks/{CurrentApplicationId}/{token}?wait=true", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options); } - public async Task ModifyInteractionFollowupMessageAsync(ModifyInteractionResponseParams args, ulong id, string token, RequestOptions options = null) + public Task ModifyInteractionFollowupMessageAsync(ModifyInteractionResponseParams args, ulong id, string token, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(id, 0, nameof(id)); @@ -1537,47 +1555,47 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{token}/messages/{id}", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"webhooks/{CurrentApplicationId}/{token}/messages/{id}", args, new BucketIds(), options: options); } - public async Task DeleteInteractionFollowupMessageAsync(ulong id, string token, RequestOptions options = null) + public Task DeleteInteractionFollowupMessageAsync(ulong id, string token, RequestOptions options = null) { Preconditions.NotEqual(id, 0, nameof(id)); options = RequestOptions.CreateOrClone(options); - await SendAsync("DELETE", () => $"webhooks/{CurrentApplicationId}/{token}/messages/{id}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"webhooks/{CurrentApplicationId}/{token}/messages/{id}", new BucketIds(), options: options); } #endregion #region Application Command permissions - public async Task GetGuildApplicationCommandPermissionsAsync(ulong guildId, RequestOptions options = null) + public Task GetGuildApplicationCommandPermissionsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/permissions", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/permissions", new BucketIds(), options: options); } - public async Task GetGuildApplicationCommandPermissionAsync(ulong guildId, ulong commandId, RequestOptions options = null) + public Task GetGuildApplicationCommandPermissionAsync(ulong guildId, ulong commandId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(commandId, 0, nameof(commandId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}/permissions", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}/permissions", new BucketIds(), options: options); } - public async Task ModifyApplicationCommandPermissionsAsync(ModifyGuildApplicationCommandPermissionsParams permissions, ulong guildId, ulong commandId, RequestOptions options = null) + public Task ModifyApplicationCommandPermissionsAsync(ModifyGuildApplicationCommandPermissionsParams permissions, ulong guildId, ulong commandId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(commandId, 0, nameof(commandId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}/permissions", permissions, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/guilds/{guildId}/commands/{commandId}/permissions", permissions, new BucketIds(), options: options); } public async Task> BatchModifyApplicationCommandPermissionsAsync(ModifyGuildApplicationCommandPermissions[] permissions, ulong guildId, RequestOptions options = null) @@ -1604,32 +1622,36 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task CreateGuildAsync(CreateGuildParams args, RequestOptions options = null) + + public Task CreateGuildAsync(CreateGuildParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); Preconditions.NotNullOrWhitespace(args.RegionId, nameof(args.RegionId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("POST", () => "guilds", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => "guilds", args, new BucketIds(), options: options); } - public async Task DeleteGuildAsync(ulong guildId, RequestOptions options = null) + + public Task DeleteGuildAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("DELETE", () => $"guilds/{guildId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}", ids, options: options); } - public async Task LeaveGuildAsync(ulong guildId, RequestOptions options = null) + + public Task LeaveGuildAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("DELETE", () => $"users/@me/guilds/{guildId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"users/@me/guilds/{guildId}", ids, options: options); } - public async Task ModifyGuildAsync(ulong guildId, Rest.ModifyGuildParams args, RequestOptions options = null) + + public Task ModifyGuildAsync(ulong guildId, Rest.ModifyGuildParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1641,9 +1663,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}", args, ids, options: options); } - public async Task BeginGuildPruneAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) + + public Task BeginGuildPruneAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1651,9 +1674,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("POST", () => $"guilds/{guildId}/prune", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"guilds/{guildId}/prune", args, ids, options: options); } - public async Task GetGuildPruneCountAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) + + public Task GetGuildPruneCountAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1662,7 +1686,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options); } public async Task ModifyGuildIncidentActionsAsync(ulong guildId, ModifyGuildIncidentsDataParams args, RequestOptions options = null) @@ -1677,7 +1701,7 @@ namespace Discord.API #endregion #region Guild Bans - public async Task> GetGuildBansAsync(ulong guildId, GetGuildBansParams args, RequestOptions options = null) + public Task> GetGuildBansAsync(ulong guildId, GetGuildBansParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1699,8 +1723,9 @@ namespace Discord.API endpoint = () => $"guilds/{guildId}/bans?limit={limit}&{relativeDir}={relativeId}"; else endpoint = () => $"guilds/{guildId}/bans?limit={limit}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", endpoint, ids, options: options); } + public async Task GetGuildBanAsync(ulong guildId, ulong userId, RequestOptions options) { Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1714,13 +1739,14 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } + /// /// and must not be equal to zero. /// -and- /// must be between 0 to 7. /// /// must not be . - public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) + public Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1732,17 +1758,18 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); if (!string.IsNullOrWhiteSpace(args.Reason)) options.AuditLogReason = args.Reason; - await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete_message_days={args.DeleteMessageDays}", ids, options: options).ConfigureAwait(false); + return SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete_message_days={args.DeleteMessageDays}", ids, options: options); } + /// and must not be equal to zero. - public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) + public Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options); } #endregion @@ -1760,37 +1787,39 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } + /// must not be equal to zero. /// must not be . - public async Task ModifyGuildWidgetAsync(ulong guildId, Rest.ModifyGuildWidgetParams args, RequestOptions options = null) + public Task ModifyGuildWidgetAsync(ulong guildId, Rest.ModifyGuildWidgetParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/widget", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/widget", args, ids, options: options); } #endregion #region Guild Integrations /// must not be equal to zero. - public async Task> GetIntegrationsAsync(ulong guildId, RequestOptions options = null) + public Task> GetIntegrationsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/integrations", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/integrations", ids, options: options); } - public async Task DeleteIntegrationAsync(ulong guildId, ulong integrationId, RequestOptions options = null) + + public Task DeleteIntegrationAsync(ulong guildId, ulong integrationId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(integrationId, 0, nameof(integrationId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"guilds/{guildId}/integrations/{integrationId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/integrations/{integrationId}", ids, options: options); } #endregion @@ -1820,33 +1849,37 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } + /// may not be equal to zero. - public async Task GetVanityInviteAsync(ulong guildId, RequestOptions options = null) + public Task GetVanityInviteAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/vanity-url", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/vanity-url", ids, options: options); } + /// may not be equal to zero. - public async Task> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null) + public Task> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/invites", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/invites", ids, options: options); } + /// may not be equal to zero. - public async Task> GetChannelInvitesAsync(ulong channelId, RequestOptions options = null) + public Task> GetChannelInvitesAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendAsync>("GET", () => $"channels/{channelId}/invites", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"channels/{channelId}/invites", ids, options: options); } + /// /// may not be equal to zero. /// -and- @@ -1855,7 +1888,7 @@ namespace Discord.API /// must be lesser than 86400. /// /// must not be . - public async Task CreateChannelInviteAsync(ulong channelId, CreateChannelInviteParams args, RequestOptions options = null) + public Task CreateChannelInviteAsync(ulong channelId, CreateChannelInviteParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -1874,19 +1907,20 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/invites", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{channelId}/invites", args, ids, options: options); } - public async Task DeleteInviteAsync(string inviteId, RequestOptions options = null) + + public Task DeleteInviteAsync(string inviteId, RequestOptions options = null) { Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options); } #endregion #region Guild Members - public async Task AddGuildMemberAsync(ulong guildId, ulong userId, AddGuildMemberParams args, RequestOptions options = null) + public Task AddGuildMemberAsync(ulong guildId, ulong userId, AddGuildMemberParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1902,9 +1936,9 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - return await SendJsonAsync("PUT", () => $"guilds/{guildId}/members/{userId}", args, ids, options: options); + return SendJsonAsync("PUT", () => $"guilds/{guildId}/members/{userId}", args, ids, options: options); } + public async Task GetGuildMemberAsync(ulong guildId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1918,7 +1952,8 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetGuildMembersAsync(ulong guildId, GetGuildMembersParams args, RequestOptions options = null) + + public Task> GetGuildMembersAsync(ulong guildId, GetGuildMembersParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1932,9 +1967,10 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); Expression> endpoint = () => $"guilds/{guildId}/members?limit={limit}&after={afterUserId}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", endpoint, ids, options: options); } - public async Task RemoveGuildMemberAsync(ulong guildId, ulong userId, string reason, RequestOptions options = null) + + public Task RemoveGuildMemberAsync(ulong guildId, ulong userId, string reason, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1943,8 +1979,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); if (!string.IsNullOrWhiteSpace(reason)) options.AuditLogReason = reason; - await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}", ids, options: options); } + public async Task ModifyGuildMemberAsync(ulong guildId, ulong userId, Rest.ModifyGuildMemberParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1966,7 +2003,8 @@ namespace Discord.API await SendJsonAsync("PATCH", () => $"guilds/{guildId}/members/{userId}", args, ids, options: options).ConfigureAwait(false); } } - public async Task> SearchGuildMembersAsync(ulong guildId, SearchGuildMembersParams args, RequestOptions options = null) + + public Task> SearchGuildMembersAsync(ulong guildId, SearchGuildMembersParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -1980,19 +2018,20 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); Expression> endpoint = () => $"guilds/{guildId}/members/search?limit={limit}&query={query}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", endpoint, ids, options: options); } #endregion #region Guild Roles - public async Task> GetGuildRolesAsync(ulong guildId, RequestOptions options = null) + public Task> GetGuildRolesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/roles", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/roles", ids, options: options); } + public async Task CreateGuildRoleAsync(ulong guildId, Rest.ModifyGuildRoleParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -2001,16 +2040,18 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendJsonAsync("POST", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); } - public async Task DeleteGuildRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) + + public Task DeleteGuildRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(roleId, 0, nameof(roleId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options); } - public async Task ModifyGuildRoleAsync(ulong guildId, ulong roleId, Rest.ModifyGuildRoleParams args, RequestOptions options = null) + + public Task ModifyGuildRoleAsync(ulong guildId, ulong roleId, Rest.ModifyGuildRoleParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(roleId, 0, nameof(roleId)); @@ -2020,40 +2061,41 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/roles/{roleId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/roles/{roleId}", args, ids, options: options); } - public async Task> ModifyGuildRolesAsync(ulong guildId, IEnumerable args, RequestOptions options = null) + + public Task> ModifyGuildRolesAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options); } #endregion #region Guild emoji - public async Task> GetGuildEmotesAsync(ulong guildId, RequestOptions options = null) + public Task> GetGuildEmotesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/emojis", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/emojis", ids, options: options); } - public async Task GetGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) + public Task GetGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(emoteId, 0, nameof(emoteId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options); } - public async Task CreateGuildEmoteAsync(ulong guildId, Rest.CreateGuildEmoteParams args, RequestOptions options = null) + public Task CreateGuildEmoteAsync(ulong guildId, Rest.CreateGuildEmoteParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -2062,10 +2104,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options); } - public async Task ModifyGuildEmoteAsync(ulong guildId, ulong emoteId, ModifyGuildEmoteParams args, RequestOptions options = null) + public Task ModifyGuildEmoteAsync(ulong guildId, ulong emoteId, ModifyGuildEmoteParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(emoteId, 0, nameof(emoteId)); @@ -2073,43 +2115,42 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options); } - public async Task DeleteGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) + public Task DeleteGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(emoteId, 0, nameof(emoteId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options); } #endregion #region Guild Events - public async Task ListGuildScheduledEventsAsync(ulong guildId, RequestOptions options = null) + public Task ListGuildScheduledEventsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/scheduled-events?with_user_count=true", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/scheduled-events?with_user_count=true", ids, options: options); } - public async Task GetGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) + public Task GetGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(eventId, 0, nameof(eventId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - return await NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}?with_user_count=true", ids, options: options)).ConfigureAwait(false); + return NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}?with_user_count=true", ids, options: options)); } - public async Task CreateGuildScheduledEventAsync(CreateGuildScheduledEventParams args, ulong guildId, RequestOptions options = null) + public Task CreateGuildScheduledEventAsync(CreateGuildScheduledEventParams args, ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -2117,11 +2158,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - return await SendJsonAsync("POST", () => $"guilds/{guildId}/scheduled-events", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"guilds/{guildId}/scheduled-events", args, ids, options: options); } - public async Task ModifyGuildScheduledEventAsync(ModifyGuildScheduledEventParams args, ulong eventId, ulong guildId, RequestOptions options = null) + public Task ModifyGuildScheduledEventAsync(ModifyGuildScheduledEventParams args, ulong eventId, ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(eventId, 0, nameof(eventId)); @@ -2130,11 +2170,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/scheduled-events/{eventId}", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/scheduled-events/{eventId}", args, ids, options: options); } - public async Task DeleteGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) + public Task DeleteGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(eventId, 0, nameof(eventId)); @@ -2142,11 +2181,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - await SendAsync("DELETE", () => $"guilds/{guildId}/scheduled-events/{eventId}", ids, options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"guilds/{guildId}/scheduled-events/{eventId}", ids, options: options); } - public async Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, int limit = 100, RequestOptions options = null) + public Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, int limit = 100, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(eventId, 0, nameof(eventId)); @@ -2154,11 +2192,10 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - - return await SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}/users?limit={limit}&with_member=true", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}/users?limit={limit}&with_member=true", ids, options: options); } - public async Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, GetEventUsersParams args, RequestOptions options = null) + public Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, GetEventUsersParams args, RequestOptions options = null) { Preconditions.NotEqual(eventId, 0, nameof(eventId)); Preconditions.NotNull(args, nameof(args)); @@ -2181,59 +2218,59 @@ namespace Discord.API else endpoint = () => $"guilds/{guildId}/scheduled-events/{eventId}/users?with_member=true&limit={limit}"; - return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync("GET", endpoint, ids, options: options); } #endregion #region Guild AutoMod - public async Task GetGuildAutoModRulesAsync(ulong guildId, RequestOptions options) + public Task GetGuildAutoModRulesAsync(ulong guildId, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"guilds/{guildId}/auto-moderation/rules", new BucketIds(guildId: guildId), options: options); + return SendAsync("GET", () => $"guilds/{guildId}/auto-moderation/rules", new BucketIds(guildId: guildId), options: options); } - public async Task GetGuildAutoModRuleAsync(ulong guildId, ulong ruleId, RequestOptions options) + public Task GetGuildAutoModRuleAsync(ulong guildId, ulong ruleId, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(ruleId, 0, nameof(ruleId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", new BucketIds(guildId), options: options); + return SendAsync("GET", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", new BucketIds(guildId), options: options); } - public async Task CreateGuildAutoModRuleAsync(ulong guildId, CreateAutoModRuleParams args, RequestOptions options) + public Task CreateGuildAutoModRuleAsync(ulong guildId, CreateAutoModRuleParams args, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("POST", () => $"guilds/{guildId}/auto-moderation/rules", args, new BucketIds(guildId: guildId), options: options); + return SendJsonAsync("POST", () => $"guilds/{guildId}/auto-moderation/rules", args, new BucketIds(guildId: guildId), options: options); } - public async Task ModifyGuildAutoModRuleAsync(ulong guildId, ulong ruleId, ModifyAutoModRuleParams args, RequestOptions options) + public Task ModifyGuildAutoModRuleAsync(ulong guildId, ulong ruleId, ModifyAutoModRuleParams args, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(ruleId, 0, nameof(ruleId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", args, new BucketIds(guildId: guildId), options: options); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", args, new BucketIds(guildId: guildId), options: options); } - public async Task DeleteGuildAutoModRuleAsync(ulong guildId, ulong ruleId, RequestOptions options) + public Task DeleteGuildAutoModRuleAsync(ulong guildId, ulong ruleId, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(ruleId, 0, nameof(ruleId)); options = RequestOptions.CreateOrClone(options); - await SendAsync("DELETE", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", new BucketIds(guildId: guildId), options: options); + return SendAsync("DELETE", () => $"guilds/{guildId}/auto-moderation/rules/{ruleId}", new BucketIds(guildId: guildId), options: options); } #endregion @@ -2253,7 +2290,7 @@ namespace Discord.API catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task ModifyGuildWelcomeScreenAsync(ModifyGuildWelcomeScreenParams args, ulong guildId, RequestOptions options = null) + public Task ModifyGuildWelcomeScreenAsync(ModifyGuildWelcomeScreenParams args, ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -2262,29 +2299,29 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/welcome-screen", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/welcome-screen", args, ids, options: options); } #endregion #region Guild Onboarding - public async Task GetGuildOnboardingAsync(ulong guildId, RequestOptions options) + public Task GetGuildOnboardingAsync(ulong guildId, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => $"guilds/{guildId}/onboarding", new BucketIds(guildId: guildId), options: options); + return SendAsync("GET", () => $"guilds/{guildId}/onboarding", new BucketIds(guildId: guildId), options: options); } - public async Task ModifyGuildOnboardingAsync(ulong guildId, ModifyGuildOnboardingParams args, RequestOptions options) + public Task ModifyGuildOnboardingAsync(ulong guildId, ModifyGuildOnboardingParams args, RequestOptions options) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PUT", () => $"guilds/{guildId}/onboarding", args, new BucketIds(guildId: guildId), options: options); + return SendJsonAsync("PUT", () => $"guilds/{guildId}/onboarding", args, new BucketIds(guildId: guildId), options: options); } #endregion @@ -2304,22 +2341,25 @@ namespace Discord.API #endregion #region Current User/DMs - public async Task GetMyUserAsync(RequestOptions options = null) + public Task GetMyUserAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => "users/@me", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "users/@me", new BucketIds(), options: options); } - public async Task> GetMyConnectionsAsync(RequestOptions options = null) + + public Task> GetMyConnectionsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync>("GET", () => "users/@me/connections", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync>("GET", () => "users/@me/connections", new BucketIds(), options: options); } - public async Task> GetMyPrivateChannelsAsync(RequestOptions options = null) + + public Task> GetMyPrivateChannelsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync>("GET", () => "users/@me/channels", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync>("GET", () => "users/@me/channels", new BucketIds(), options: options); } - public async Task> GetMyGuildsAsync(GetGuildSummariesParams args, RequestOptions options = null) + + public Task> GetMyGuildsAsync(GetGuildSummariesParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); @@ -2330,82 +2370,85 @@ namespace Discord.API int limit = args.Limit.GetValueOrDefault(int.MaxValue); ulong afterGuildId = args.AfterGuildId.GetValueOrDefault(0); - return await SendAsync>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}&with_counts=true", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}&with_counts=true", new BucketIds(), options: options); } - public async Task GetMyApplicationAsync(RequestOptions options = null) + public Task GetMyApplicationAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => "oauth2/applications/@me", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "oauth2/applications/@me", new BucketIds(), options: options); } - public async Task GetCurrentBotApplicationAsync(RequestOptions options = null) + public Task GetCurrentBotApplicationAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", () => "applications/@me", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => "applications/@me", new BucketIds(), options: options); } - public async Task ModifyCurrentBotApplicationAsync(ModifyCurrentApplicationBotParams args, RequestOptions options = null) + public Task ModifyCurrentBotApplicationAsync(ModifyCurrentApplicationBotParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => "applications/@me", args, new BucketIds(), options: options); + return SendJsonAsync("PATCH", () => "applications/@me", args, new BucketIds(), options: options); } - public async Task ModifySelfAsync(Rest.ModifyCurrentUserParams args, RequestOptions options = null) + public Task ModifySelfAsync(Rest.ModifyCurrentUserParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotNullOrEmpty(args.Username, nameof(args.Username)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("PATCH", () => "users/@me", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => "users/@me", args, new BucketIds(), options: options); } - public async Task ModifyMyNickAsync(ulong guildId, Rest.ModifyCurrentUserNickParams args, RequestOptions options = null) + + public Task ModifyMyNickAsync(ulong guildId, Rest.ModifyCurrentUserNickParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotNull(args.Nickname, nameof(args.Nickname)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - await SendJsonAsync("PATCH", () => $"guilds/{guildId}/members/@me/nick", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"guilds/{guildId}/members/@me/nick", args, ids, options: options); } - public async Task CreateDMChannelAsync(CreateDMChannelParams args, RequestOptions options = null) + + public Task CreateDMChannelAsync(CreateDMChannelParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.GreaterThan(args.RecipientId, 0, nameof(args.RecipientId)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("POST", () => "users/@me/channels", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => "users/@me/channels", args, new BucketIds(), options: options); } - public async Task GetCurrentUserGuildMember(ulong guildId, RequestOptions options = null) + public Task GetCurrentUserGuildMember(ulong guildId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(); - return await SendAsync("GET", () => $"users/@me/guilds/{guildId}/member", ids, options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"users/@me/guilds/{guildId}/member", ids, options: options); } #endregion #region Voice Regions - public async Task> GetVoiceRegionsAsync(RequestOptions options = null) + public Task> GetVoiceRegionsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync>("GET", () => "voice/regions", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync>("GET", () => "voice/regions", new BucketIds(), options: options); } - public async Task> GetGuildVoiceRegionsAsync(ulong guildId, RequestOptions options = null) + + public Task> GetGuildVoiceRegionsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/regions", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/regions", ids, options: options); } #endregion #region Audit logs - public async Task GetAuditLogsAsync(ulong guildId, GetAuditLogsParams args, RequestOptions options = null) + public Task GetAuditLogsAsync(ulong guildId, GetAuditLogsParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -2440,12 +2483,12 @@ namespace Discord.API // Still use string interpolation for the query w/o params, as this is necessary for CreateBucketId endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}{queryArgs.ToString()}"; - return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false); + return SendAsync("GET", endpoint, ids, options: options); } #endregion #region Webhooks - public async Task CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) + public Task CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -2453,8 +2496,9 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options).ConfigureAwait(false); + return SendJsonAsync("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options); } + public async Task GetWebhookAsync(ulong webhookId, RequestOptions options = null) { Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); @@ -2469,7 +2513,8 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task ModifyWebhookAsync(ulong webhookId, ModifyWebhookParams args, RequestOptions options = null) + + public Task ModifyWebhookAsync(ulong webhookId, ModifyWebhookParams args, RequestOptions options = null) { Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); Preconditions.NotNull(args, nameof(args)); @@ -2477,35 +2522,38 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); if (AuthTokenType == TokenType.Webhook) - return await SendJsonAsync("PATCH", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), options: options); else - return await SendJsonAsync("PATCH", () => $"webhooks/{webhookId}", args, new BucketIds(), options: options).ConfigureAwait(false); + return SendJsonAsync("PATCH", () => $"webhooks/{webhookId}", args, new BucketIds(), options: options); } - public async Task DeleteWebhookAsync(ulong webhookId, RequestOptions options = null) + + public Task DeleteWebhookAsync(ulong webhookId, RequestOptions options = null) { Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); options = RequestOptions.CreateOrClone(options); if (AuthTokenType == TokenType.Webhook) - await SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}", new BucketIds(), options: options); else - await SendAsync("DELETE", () => $"webhooks/{webhookId}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("DELETE", () => $"webhooks/{webhookId}", new BucketIds(), options: options); } - public async Task> GetGuildWebhooksAsync(ulong guildId, RequestOptions options = null) + + public Task> GetGuildWebhooksAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync>("GET", () => $"guilds/{guildId}/webhooks", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"guilds/{guildId}/webhooks", ids, options: options); } - public async Task> GetChannelWebhooksAsync(ulong channelId, RequestOptions options = null) + + public Task> GetChannelWebhooksAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); - return await SendAsync>("GET", () => $"channels/{channelId}/webhooks", ids, options: options).ConfigureAwait(false); + return SendAsync>("GET", () => $"channels/{channelId}/webhooks", ids, options: options); } #endregion @@ -2700,29 +2748,29 @@ namespace Discord.API #region Application Role Connections Metadata - public async Task GetApplicationRoleConnectionMetadataRecordsAsync(RequestOptions options = null) - => await SendAsync("GET", () => $"applications/{CurrentApplicationId}/role-connections/metadata", new BucketIds(), options: options).ConfigureAwait(false); + public Task GetApplicationRoleConnectionMetadataRecordsAsync(RequestOptions options = null) + => SendAsync("GET", () => $"applications/{CurrentApplicationId}/role-connections/metadata", new BucketIds(), options: options); - public async Task UpdateApplicationRoleConnectionMetadataRecordsAsync(RoleConnectionMetadata[] roleConnections, RequestOptions options = null) - => await SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/role-connections/metadata", roleConnections, new BucketIds(), options: options).ConfigureAwait(false); + public Task UpdateApplicationRoleConnectionMetadataRecordsAsync(RoleConnectionMetadata[] roleConnections, RequestOptions options = null) + => SendJsonAsync("PUT", () => $"applications/{CurrentApplicationId}/role-connections/metadata", roleConnections, new BucketIds(), options: options); - public async Task GetUserApplicationRoleConnectionAsync(ulong applicationId, RequestOptions options = null) - => await SendAsync("GET", () => $"users/@me/applications/{applicationId}/role-connection", new BucketIds(), options: options); + public Task GetUserApplicationRoleConnectionAsync(ulong applicationId, RequestOptions options = null) + => SendAsync("GET", () => $"users/@me/applications/{applicationId}/role-connection", new BucketIds(), options: options); - public async Task ModifyUserApplicationRoleConnectionAsync(ulong applicationId, RoleConnection connection, RequestOptions options = null) - => await SendJsonAsync("PUT", () => $"users/@me/applications/{applicationId}/role-connection", connection, new BucketIds(), options: options); + public Task ModifyUserApplicationRoleConnectionAsync(ulong applicationId, RoleConnection connection, RequestOptions options = null) + => SendJsonAsync("PUT", () => $"users/@me/applications/{applicationId}/role-connection", connection, new BucketIds(), options: options); #endregion #region App Monetization - public async Task CreateEntitlementAsync(CreateEntitlementParams args, RequestOptions options = null) - => await SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/entitlements", args, new BucketIds(), options: options).ConfigureAwait(false); + public Task CreateEntitlementAsync(CreateEntitlementParams args, RequestOptions options = null) + => SendJsonAsync("POST", () => $"applications/{CurrentApplicationId}/entitlements", args, new BucketIds(), options: options); - public async Task DeleteEntitlementAsync(ulong entitlementId, RequestOptions options = null) - => await SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/entitlements/{entitlementId}", new BucketIds(), options: options).ConfigureAwait(false); + public Task DeleteEntitlementAsync(ulong entitlementId, RequestOptions options = null) + => SendAsync("DELETE", () => $"applications/{CurrentApplicationId}/entitlements/{entitlementId}", new BucketIds(), options: options); - public async Task ListEntitlementAsync(ListEntitlementsParams args, RequestOptions options = null) + public Task ListEntitlementAsync(ListEntitlementsParams args, RequestOptions options = null) { var query = $"?limit={args.Limit.GetValueOrDefault(100)}"; @@ -2756,11 +2804,11 @@ namespace Discord.API query += $"&exclude_ended={args.ExcludeEnded.Value}"; } - return await SendAsync("GET", () => $"applications/{CurrentApplicationId}/entitlements{query}", new BucketIds(), options: options).ConfigureAwait(false); + return SendAsync("GET", () => $"applications/{CurrentApplicationId}/entitlements{query}", new BucketIds(), options: options); } - public async Task ListSKUsAsync(RequestOptions options = null) - => await SendAsync("GET", () => $"applications/{CurrentApplicationId}/skus", new BucketIds(), options: options).ConfigureAwait(false); + public Task ListSKUsAsync(RequestOptions options = null) + => SendAsync("GET", () => $"applications/{CurrentApplicationId}/skus", new BucketIds(), options: options); #endregion } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index a5dd522f..3063ccfd 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -13,12 +13,10 @@ namespace Discord.Rest internal static class ChannelHelper { #region General - public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); - } - public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, + public static Task DeleteAsync(IChannel channel, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteChannelAsync(channel.Id, options); + + public static Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, Action func, RequestOptions options) { @@ -40,9 +38,10 @@ namespace Discord.Rest : Optional.Create(), Flags = args.Flags.GetValueOrDefault(), }; - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options); } - public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, + + public static Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, Action func, RequestOptions options) { @@ -67,9 +66,10 @@ namespace Discord.Rest : Optional.Create(), DefaultSlowModeInterval = args.DefaultSlowModeInterval }; - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options); } - public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, + + public static Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, Action func, RequestOptions options) { @@ -95,10 +95,10 @@ namespace Discord.Rest SlowModeInterval = args.SlowModeInterval, IsNsfw = args.IsNsfw, }; - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options); } - public static async Task ModifyAsync(IStageChannel channel, BaseDiscordClient client, + public static Task ModifyAsync(IStageChannel channel, BaseDiscordClient client, Action func, RequestOptions options = null) { var args = new StageInstanceProperties(); @@ -110,7 +110,7 @@ namespace Discord.Rest Topic = args.Topic }; - return await client.ApiClient.ModifyStageInstanceAsync(channel.Id, apiArgs, options); + return client.ApiClient.ModifyStageInstanceAsync(channel.Id, apiArgs, options); } #endregion @@ -492,28 +492,27 @@ namespace Discord.Rest #endregion #region Permission Overwrites - public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, + public static Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IUser user, OverwritePermissions perms, RequestOptions options) { var args = new ModifyChannelPermissionsParams((int)PermissionTarget.User, perms.AllowValue.ToString(), perms.DenyValue.ToString()); - await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false); + return client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options); } - public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, + + public static Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IRole role, OverwritePermissions perms, RequestOptions options) { var args = new ModifyChannelPermissionsParams((int)PermissionTarget.Role, perms.AllowValue.ToString(), perms.DenyValue.ToString()); - await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false); + return client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options); } - public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, + + public static Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IUser user, RequestOptions options) - { - await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options).ConfigureAwait(false); - } - public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, + => client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options); + + public static Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IRole role, RequestOptions options) - { - await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false); - } + => client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options); #endregion #region Users @@ -564,11 +563,9 @@ namespace Discord.Rest #endregion #region Typing - public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, - RequestOptions options = null) - { - await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false); - } + public static Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, RequestOptions options = null) + => client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options); + public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) => new TypingNotifier(channel, options); diff --git a/src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs index 9a6c0aeb..1267fed0 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs @@ -8,7 +8,7 @@ namespace Discord.Rest; internal static class ForumHelper { - public static async Task ModifyAsync(IForumChannel channel, BaseDiscordClient client, + public static Task ModifyAsync(IForumChannel channel, BaseDiscordClient client, Action func, RequestOptions options) { @@ -59,6 +59,6 @@ internal static class ForumHelper : Optional.Unspecified, DefaultSortOrder = args.DefaultSortOrder }; - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 0f2f6e23..611298a3 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -220,17 +220,17 @@ namespace Discord.Rest OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); /// - async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false); + Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) + => AddPermissionOverwriteAsync(role, permissions, options); /// - async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false); + Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) + => AddPermissionOverwriteAsync(user, permissions, options); /// - async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) - => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); + Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) + => RemovePermissionOverwriteAsync(role, options); /// - async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) - => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); + Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) + => RemovePermissionOverwriteAsync(user, options); /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs index 0108d3dc..cbfd6114 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs @@ -11,7 +11,7 @@ namespace Discord.Rest { internal static class ThreadHelper { - public static async Task CreateThreadAsync(BaseDiscordClient client, ITextChannel channel, string name, ThreadType type = ThreadType.PublicThread, + public static Task CreateThreadAsync(BaseDiscordClient client, ITextChannel channel, string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) { if (channel is INewsChannel && type != ThreadType.NewsThread) @@ -26,17 +26,13 @@ namespace Discord.Rest Ratelimit = slowmode.HasValue ? slowmode.Value : Optional.Unspecified, }; - Model model; - if (message != null) - model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false); + return client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options); else - model = await client.ApiClient.StartThreadAsync(channel.Id, args, options).ConfigureAwait(false); - - return model; + return client.ApiClient.StartThreadAsync(channel.Id, args, options); } - public static async Task ModifyAsync(IThreadChannel channel, BaseDiscordClient client, + public static Task ModifyAsync(IThreadChannel channel, BaseDiscordClient client, Action func, RequestOptions options) { @@ -55,7 +51,7 @@ namespace Discord.Rest AppliedTags = args.AppliedTags, Flags = args.Flags, }; - return await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options); } public static async Task> GetActiveThreadsAsync(IGuild guild, ulong channelId, BaseDiscordClient client, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 87222879..7558ee4c 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -20,7 +20,7 @@ namespace Discord.Rest { #region General /// is . - public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, + public static Task ModifyAsync(IGuild guild, BaseDiscordClient client, Action func, RequestOptions options) { if (func == null) @@ -91,10 +91,11 @@ namespace Discord.Rest else if (args.PreferredCulture.IsSpecified) apiArgs.PreferredLocale = args.PreferredCulture.Value.Name; - return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options); } + /// is . - public static async Task ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, + public static Task ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, Action func, RequestOptions options) { if (func == null) @@ -112,30 +113,29 @@ namespace Discord.Rest else if (args.ChannelId.IsSpecified) apiArgs.ChannelId = args.ChannelId.Value; - return await client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options); } - public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, + + public static Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, IEnumerable args, RequestOptions options) { var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position)); - await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options); } - public static async Task> ReorderRolesAsync(IGuild guild, BaseDiscordClient client, + + public static Task> ReorderRolesAsync(IGuild guild, BaseDiscordClient client, IEnumerable args, RequestOptions options) { var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id, x.Position)); - return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false); - } - public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false); - } - public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options); } + + public static Task LeaveAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.LeaveGuildAsync(guild.Id, options); + + public static Task DeleteAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteGuildAsync(guild.Id, options); + public static ulong GetUploadLimit(IGuild guild) { var tierFactor = guild.PremiumTier switch @@ -223,17 +223,15 @@ namespace Discord.Rest return model == null ? null : RestBan.Create(client, model); } - public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, + public static Task AddBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, int pruneDays, string reason, RequestOptions options) { var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays, Reason = reason }; - await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false); - } - public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, - ulong userId, RequestOptions options) - { - await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); + return client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options); } + + public static Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) + => client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options); #endregion #region Channels @@ -506,9 +504,9 @@ namespace Discord.Rest var models = await client.ApiClient.GetIntegrationsAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestIntegration.Create(client, guild, x)).ToImmutableArray(); } - public static async Task DeleteIntegrationAsync(IGuild guild, BaseDiscordClient client, ulong id, - RequestOptions options) => - await client.ApiClient.DeleteIntegrationAsync(guild.Id, id, options).ConfigureAwait(false); + + public static Task DeleteIntegrationAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) + => client.ApiClient.DeleteIntegrationAsync(guild.Id, id, options); #endregion #region Interactions @@ -611,7 +609,7 @@ namespace Discord.Rest return model is null ? null : RestGuildUser.Create(client, guild, model); } - public static async Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken, + public static Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken, Action func, RequestOptions options) { var args = new AddGuildUserProperties(); @@ -635,7 +633,7 @@ namespace Discord.Rest RoleIds = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create() }; - await client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options); + return client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options); } public static async Task GetUserAsync(IGuild guild, BaseDiscordClient client, @@ -646,11 +644,9 @@ namespace Discord.Rest return RestGuildUser.Create(client, guild, model); return null; } - public static async Task GetCurrentUserAsync(IGuild guild, BaseDiscordClient client, - RequestOptions options) - { - return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false); - } + public static Task GetCurrentUserAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + => GetUserAsync(guild, client, client.CurrentUser.Id, options); + public static IAsyncEnumerable> GetUsersAsync(IGuild guild, BaseDiscordClient client, ulong? fromUserId, int? limit, RequestOptions options) { @@ -833,7 +829,7 @@ namespace Discord.Rest return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false); } - public static async Task CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable tags, + public static Task CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable tags, string description = null, RequestOptions options = null) { Preconditions.NotNull(name, nameof(name)); @@ -865,10 +861,10 @@ namespace Discord.Rest FileName = filename }; - return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false); + return client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options); } - public static async Task ModifyStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, Action func, + public static Task ModifyStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, Action func, RequestOptions options = null) { if (func == null) @@ -886,11 +882,11 @@ namespace Discord.Rest Optional.Unspecified }; - return await client.ApiClient.ModifyStickerAsync(apiArgs, guildId, sticker.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyStickerAsync(apiArgs, guildId, sticker.Id, options); } - public static async Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null) - => await client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options).ConfigureAwait(false); + public static Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null) + => client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options); #endregion #region Events @@ -981,7 +977,7 @@ namespace Discord.Rest ); } - public static async Task ModifyGuildEventAsync(BaseDiscordClient client, Action func, + public static Task ModifyGuildEventAsync(BaseDiscordClient client, Action func, IGuildScheduledEvent guildEvent, RequestOptions options = null) { var args = new GuildScheduledEventsProperties(); @@ -1042,7 +1038,7 @@ namespace Discord.Rest }; } - return await client.ApiClient.ModifyGuildScheduledEventAsync(apiArgs, guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildScheduledEventAsync(apiArgs, guildEvent.Id, guildEvent.Guild.Id, options); } public static async Task GetGuildEventAsync(BaseDiscordClient client, ulong id, IGuild guild, RequestOptions options = null) @@ -1123,10 +1119,8 @@ namespace Discord.Rest return RestGuildEvent.Create(client, guild, client.CurrentUser, model); } - public static async Task DeleteEventAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, RequestOptions options = null) - { - await client.ApiClient.DeleteGuildScheduledEventAsync(guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false); - } + public static Task DeleteEventAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, RequestOptions options = null) + => client.ApiClient.DeleteGuildScheduledEventAsync(guildEvent.Id, guildEvent.Guild.Id, options); #endregion @@ -1180,7 +1174,7 @@ namespace Discord.Rest #region Auto Mod - public static async Task CreateAutoModRuleAsync(IGuild guild, Action func, BaseDiscordClient client, RequestOptions options) + public static Task CreateAutoModRuleAsync(IGuild guild, Action func, BaseDiscordClient client, RequestOptions options) { var args = new AutoModRuleProperties(); func(args); @@ -1299,14 +1293,14 @@ namespace Discord.Rest }, }; - return await client.ApiClient.CreateGuildAutoModRuleAsync(guild.Id, props, options); + return client.ApiClient.CreateGuildAutoModRuleAsync(guild.Id, props, options); } - public static async Task GetAutoModRuleAsync(ulong ruleId, IGuild guild, BaseDiscordClient client, RequestOptions options) - => await client.ApiClient.GetGuildAutoModRuleAsync(guild.Id, ruleId, options); + public static Task GetAutoModRuleAsync(ulong ruleId, IGuild guild, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.GetGuildAutoModRuleAsync(guild.Id, ruleId, options); - public static async Task GetAutoModRulesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) - => await client.ApiClient.GetGuildAutoModRulesAsync(guild.Id, options); + public static Task GetAutoModRulesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.GetGuildAutoModRulesAsync(guild.Id, options); public static Task ModifyRuleAsync(BaseDiscordClient client, IAutoModRule rule, Action func, RequestOptions options) { @@ -1354,10 +1348,10 @@ namespace Discord.Rest #region Onboarding - public static async Task GetGuildOnboardingAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) - => await client.ApiClient.GetGuildOnboardingAsync(guild.Id, options); + public static Task GetGuildOnboardingAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.GetGuildOnboardingAsync(guild.Id, options); - public static async Task ModifyGuildOnboardingAsync(IGuild guild, Action func, BaseDiscordClient client, RequestOptions options) + public static Task ModifyGuildOnboardingAsync(IGuild guild, Action func, BaseDiscordClient client, RequestOptions options) { var props = new GuildOnboardingProperties(); func(props); @@ -1394,7 +1388,7 @@ namespace Discord.Rest : Optional.Unspecified, }; - return await client.ApiClient.ModifyGuildOnboardingAsync(guild.Id, args, options); + return client.ApiClient.ModifyGuildOnboardingAsync(guild.Id, args, options); } #endregion diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 486b83c9..114d37b0 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -296,10 +296,10 @@ namespace Discord.Rest /// /// is . - public async Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) + public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) { var arr = args.ToArray(); - await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options).ConfigureAwait(false); + return GuildHelper.ReorderChannelsAsync(this, Discord, arr, options); } /// public async Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null) @@ -670,12 +670,12 @@ namespace Discord.Rest /// A task that represents the asynchronous get operation. The task result contains the widget channel set /// within the server's widget settings; if none is set. /// - public async Task GetWidgetChannelAsync(RequestOptions options = null) + public Task GetWidgetChannelAsync(RequestOptions options = null) { var widgetChannelId = WidgetChannelId; if (widgetChannelId.HasValue) - return await GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options).ConfigureAwait(false); - return null; + return GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options); + return Task.FromResult(null); } /// @@ -1053,8 +1053,9 @@ namespace Discord.Rest /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of application commands found within the guild. /// - public async Task> GetApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null) - => await ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, withLocalizations, locale, options).ConfigureAwait(false); + public Task> GetApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null) + => ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, withLocalizations, locale, options); + /// /// Gets an application command within this guild with the specified id. /// @@ -1064,8 +1065,9 @@ namespace Discord.Rest /// A ValueTask that represents the asynchronous get operation. The task result contains a /// if found, otherwise . /// - public async Task GetApplicationCommandAsync(ulong id, RequestOptions options = null) - => await ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options); + public Task GetApplicationCommandAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options); + /// /// Creates an application command within this guild. /// @@ -1168,6 +1170,7 @@ namespace Discord.Rest using var fs = File.OpenRead(path); return await CreateStickerAsync(name, fs, Path.GetFileName(fs.Name), tags, description,options); } + /// /// Creates a new sticker in this guild /// @@ -1587,8 +1590,8 @@ namespace Discord.Rest async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false); /// - async Task IGuild.DeleteIntegrationAsync(ulong id, RequestOptions options) - => await DeleteIntegrationAsync(id, options).ConfigureAwait(false); + Task IGuild.DeleteIntegrationAsync(ulong id, RequestOptions options) + => DeleteIntegrationAsync(id, options); /// async Task> IGuild.GetInvitesAsync(RequestOptions options) @@ -1616,7 +1619,8 @@ namespace Discord.Rest /// /// The user to disconnect. /// A task that represents the asynchronous operation for disconnecting a user. - async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = null); + Task IGuild.DisconnectAsync(IGuildUser user) + => user.ModifyAsync(x => x.Channel = null); /// async Task IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs index e959d3a1..605319cc 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs @@ -52,10 +52,8 @@ namespace Discord.Rest ApproximatePresenceCount = model.ApproximatePresenceCount.IsSpecified ? model.ApproximatePresenceCount.Value : null; } - public async Task LeaveAsync(RequestOptions options = null) - { - await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false); - } + public Task LeaveAsync(RequestOptions options = null) + => Discord.ApiClient.LeaveGuildAsync(Id, options); public async Task GetCurrentUserGuildMemberAsync(RequestOptions options = null) { @@ -64,10 +62,8 @@ namespace Discord.Rest } /// - public async Task DeleteAsync(RequestOptions options = null) - { - await Discord.ApiClient.DeleteGuildAsync(Id, options).ConfigureAwait(false); - } + public Task DeleteAsync(RequestOptions options = null) + => Discord.ApiClient.DeleteGuildAsync(Id, options); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}{(IsOwner ? ", Owned" : "")})"; diff --git a/src/Discord.Net.Rest/Entities/Integrations/RestIntegration.cs b/src/Discord.Net.Rest/Entities/Integrations/RestIntegration.cs index d8ffca2f..efc98e02 100644 --- a/src/Discord.Net.Rest/Entities/Integrations/RestIntegration.cs +++ b/src/Discord.Net.Rest/Entities/Integrations/RestIntegration.cs @@ -77,10 +77,8 @@ namespace Discord.Rest _syncedAtTicks = model.SyncedAt.IsSpecified ? model.SyncedAt.Value.UtcTicks : null; } - public async Task DeleteAsync() - { - await Discord.ApiClient.DeleteIntegrationAsync(GuildId, Id).ConfigureAwait(false); - } + public Task DeleteAsync() + => Discord.ApiClient.DeleteIntegrationAsync(GuildId, Id); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}{(IsEnabled ? ", Enabled" : "")})"; diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs index b0175358..a36e0cc1 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs @@ -138,7 +138,7 @@ namespace Discord.Rest } /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -171,7 +171,7 @@ namespace Discord.Rest if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// @@ -235,7 +235,7 @@ namespace Discord.Rest } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -284,7 +284,7 @@ namespace Discord.Rest flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs index 828299d2..342603d0 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs @@ -34,14 +34,15 @@ namespace Discord.Rest return entity; } - internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel, bool doApiCall) + internal virtual Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel, bool doApiCall) { Name = model.Name; if (model.Resolved.IsSpecified && ResolvableData == null) { ResolvableData = new RestResolvableData(); - await ResolvableData.PopulateAsync(client, guild, channel, model, doApiCall).ConfigureAwait(false); + return ResolvableData.PopulateAsync(client, guild, channel, model, doApiCall); } + return Task.CompletedTask; } IReadOnlyCollection IApplicationCommandInteractionData.Options diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index a889aeac..0a2278e0 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -35,17 +35,13 @@ namespace Discord.Rest return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty(), options); } - public static async Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response, + public static Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response, IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null) - { - await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false); - } + => client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options); - public static async Task SendInteractionResponseAsync(BaseDiscordClient client, UploadInteractionFileParams response, + public static Task SendInteractionResponseAsync(BaseDiscordClient client, UploadInteractionFileParams response, IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null) - { - await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false); - } + => client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options); public static async Task GetOriginalResponseAsync(BaseDiscordClient client, IMessageChannel channel, IDiscordInteraction interaction, RequestOptions options = null) @@ -90,7 +86,8 @@ namespace Discord.Rest func((TArg)args); return CreateGlobalCommandAsync(client, (TArg)args, options); } - public static async Task CreateGlobalCommandAsync(BaseDiscordClient client, + + public static Task CreateGlobalCommandAsync(BaseDiscordClient client, ApplicationCommandProperties arg, RequestOptions options = null) { Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); @@ -122,10 +119,10 @@ namespace Discord.Rest : Optional.Unspecified; } - return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); + return client.ApiClient.CreateGlobalApplicationCommandAsync(model, options); } - public static async Task BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client, + public static Task BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client, ApplicationCommandProperties[] args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); @@ -166,7 +163,7 @@ namespace Discord.Rest models.Add(model); } - return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false); + return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options); } public static async Task> BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId, @@ -239,7 +236,7 @@ namespace Discord.Rest return ModifyGlobalCommandAsync(client, command, arg, options); } - public static async Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, + public static Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, ApplicationCommandProperties args, RequestOptions options = null) { if (args.Name.IsSpecified) @@ -281,15 +278,15 @@ namespace Discord.Rest : Optional.Unspecified; } - return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options); } - public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) + public static Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) { Preconditions.NotNull(command, nameof(command)); Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); - await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); + return client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options); } #endregion @@ -302,7 +299,7 @@ namespace Discord.Rest return CreateGuildCommandAsync(client, guildId, (TArg)args, options); } - public static async Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, + public static Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties arg, RequestOptions options = null) { var model = new CreateApplicationCommandParams @@ -332,7 +329,7 @@ namespace Discord.Rest : Optional.Unspecified; } - return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); + return client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options); } public static Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, @@ -343,7 +340,7 @@ namespace Discord.Rest return ModifyGuildCommandAsync(client, command, guildId, arg, options); } - public static async Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, + public static Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, ApplicationCommandProperties arg, RequestOptions options = null) { var model = new ModifyApplicationCommandParams @@ -369,15 +366,15 @@ namespace Discord.Rest : Optional.Unspecified; } - return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options); } - public static async Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null) + public static Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null) { Preconditions.NotNull(command, nameof(command)); Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); - await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); + return client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options); } public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null) @@ -389,7 +386,7 @@ namespace Discord.Rest #endregion #region Responses - public static async Task ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action func, + public static Task ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action func, RequestOptions options = null) { var args = new MessageProperties(); @@ -429,11 +426,13 @@ namespace Discord.Rest : Optional.Unspecified, }; - return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false); + return client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options); } - public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) - => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); - public static async Task ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action func, + + public static Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) + => client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); + + public static Task ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action func, RequestOptions options = null) { var args = new MessageProperties(); @@ -476,7 +475,7 @@ namespace Discord.Rest Flags = args.Flags }; - return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false); + return client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options); } else { @@ -492,15 +491,15 @@ namespace Discord.Rest : Optional.Unspecified }; - return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false); + return client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options); } } - public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) - => await client.ApiClient.DeleteInteractionResponseAsync(message.Token, options); + public static Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) + => client.ApiClient.DeleteInteractionResponseAsync(message.Token, options); - public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, IDiscordInteraction interaction, RequestOptions options = null) - => await client.ApiClient.DeleteInteractionResponseAsync(interaction.Token, options); + public static Task DeleteInteractionResponseAsync(BaseDiscordClient client, IDiscordInteraction interaction, RequestOptions options = null) + => client.ApiClient.DeleteInteractionResponseAsync(interaction.Token, options); public static Task SendAutocompleteResultAsync(BaseDiscordClient client, IEnumerable result, ulong interactionId, string interactionToken, RequestOptions options) @@ -523,10 +522,10 @@ namespace Discord.Rest return client.ApiClient.CreateInteractionResponseAsync(apiArgs, interactionId, interactionToken, options); } - public static async Task RespondWithPremiumRequiredAsync(BaseDiscordClient client, ulong interactionId, + public static Task RespondWithPremiumRequiredAsync(BaseDiscordClient client, ulong interactionId, string interactionToken, RequestOptions options = null) { - await client.ApiClient.CreateInteractionResponseAsync(new InteractionResponse + return client.ApiClient.CreateInteractionResponseAsync(new InteractionResponse { Type = InteractionResponseType.PremiumRequired, Data = Optional.Unspecified diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs index 360fd2b4..130f03f3 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs @@ -243,7 +243,7 @@ namespace Discord.Rest } /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -276,7 +276,7 @@ namespace Discord.Rest if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// @@ -340,7 +340,7 @@ namespace Discord.Rest } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -389,7 +389,7 @@ namespace Discord.Rest flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs b/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs index 3e7a0266..f4c8c2bf 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs @@ -128,7 +128,7 @@ namespace Discord.Rest /// /// The sent message. /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -161,7 +161,7 @@ namespace Discord.Rest if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// @@ -180,7 +180,7 @@ namespace Discord.Rest /// /// The sent message. /// - public override async Task FollowupWithFileAsync( + public override Task FollowupWithFileAsync( Stream fileStream, string fileName, string text = null, @@ -218,7 +218,7 @@ namespace Discord.Rest if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// @@ -368,7 +368,7 @@ namespace Discord.Rest } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -417,7 +417,7 @@ namespace Discord.Rest flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs index c319bcf3..dce381b5 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs @@ -20,8 +20,8 @@ namespace Discord.Rest } /// - public override async Task DeleteAsync(RequestOptions options = null) - => await InteractionHelper.DeleteGlobalCommandAsync(Discord, this).ConfigureAwait(false); + public override Task DeleteAsync(RequestOptions options = null) + => InteractionHelper.DeleteGlobalCommandAsync(Discord, this); /// /// Modifies this . diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs index 9d9ecc91..41a5d1b9 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs @@ -28,8 +28,8 @@ namespace Discord.Rest } /// - public override async Task DeleteAsync(RequestOptions options = null) - => await InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this).ConfigureAwait(false); + public override Task DeleteAsync(RequestOptions options = null) + => InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this); /// /// Modifies this . diff --git a/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs b/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs index 95f2d902..c697b48d 100644 --- a/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs +++ b/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs @@ -4,10 +4,7 @@ namespace Discord.Rest { internal static class InviteHelper { - public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false); - } + public static Task DeleteAsync(IInvite invite, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteInviteAsync(invite.Code, options); } } diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 8e7f9377..a9d5c1f9 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -29,7 +29,7 @@ namespace Discord.Rest RequestOptions options) => ModifyAsync(msg.Channel.Id, msg.Id, client, func, options); - public static async Task ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action func, + public static Task ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action func, RequestOptions options) { var args = new MessageProperties(); @@ -95,7 +95,7 @@ namespace Discord.Rest AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create(), Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified, }; - return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options); } else { @@ -110,58 +110,39 @@ namespace Discord.Rest MessageComponent = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified }; - return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options); } } public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) => DeleteAsync(msg.Channel.Id, msg.Id, client, options); - public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); - } + public static Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteMessageAsync(channelId, msgId, options); - public static async Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); - public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); - public static async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveReactionAsync(channelId, messageId, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveReactionAsync(channelId, messageId, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); - public static async Task RemoveReactionAsync(IMessage msg, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task RemoveReactionAsync(IMessage msg, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); - public static async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveAllReactionsAsync(channelId, messageId, options).ConfigureAwait(false); - } + public static Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveAllReactionsAsync(channelId, messageId, options); - public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); - } + public static Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options); - public static async Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); - public static async Task RemoveAllReactionsForEmoteAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); - } + public static Task RemoveAllReactionsForEmoteAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options); public static IAsyncEnumerable> GetReactionUsersAsync(IMessage msg, IEmote emote, int? limit, BaseDiscordClient client, ReactionType reactionType, RequestOptions options) @@ -211,19 +192,15 @@ namespace Discord.Rest return newContent; } - public static async Task PinAsync(IMessage msg, BaseDiscordClient client, - RequestOptions options) + public static Task PinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { if (msg.Channel is IVoiceChannel) throw new NotSupportedException("Pinned messages are not supported in text-in-voice channels."); - await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); + return client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options); } - public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); - } + public static Task UnpinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options); public static ImmutableArray ParseTags(string text, IMessageChannel channel, IGuild guild, IReadOnlyCollection userMentions) { @@ -397,11 +374,8 @@ namespace Discord.Rest public static Task CrosspostAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) => CrosspostAsync(msg.Channel.Id, msg.Id, client, options); - public static async Task CrosspostAsync(ulong channelId, ulong msgId, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.CrosspostAsync(channelId, msgId, options).ConfigureAwait(false); - } + public static Task CrosspostAsync(ulong channelId, ulong msgId, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.CrosspostAsync(channelId, msgId, options); public static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) { diff --git a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs index d9daf5a7..dc5c1f59 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs @@ -188,14 +188,14 @@ namespace Discord.Rest /// /// This operation may only be called on a channel. - public async Task CrosspostAsync(RequestOptions options = null) + public Task CrosspostAsync(RequestOptions options = null) { if (!(Channel is INewsChannel)) { throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); } - await MessageHelper.CrosspostAsync(this, Discord, options); + return MessageHelper.CrosspostAsync(this, Discord, options); } private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index 1f1cad35..0586f6ba 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -8,11 +8,9 @@ namespace Discord.Rest internal static class RoleHelper { #region General - public static async Task DeleteAsync(IRole role, BaseDiscordClient client, - RequestOptions options) - { - await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); - } + public static Task DeleteAsync(IRole role, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options); + public static async Task ModifyAsync(IRole role, BaseDiscordClient client, Action func, RequestOptions options) { diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index 965d83d2..301bd9b9 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -10,8 +10,7 @@ namespace Discord.Rest { internal static class UserHelper { - public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action func, - RequestOptions options) + public static Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action func, RequestOptions options) { var args = new SelfUserProperties(); func(args); @@ -24,7 +23,7 @@ namespace Discord.Rest if (!apiArgs.Avatar.IsSpecified && user.AvatarId != null) apiArgs.Avatar = new ImageModel(user.AvatarId); - return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifySelfAsync(apiArgs, options); } public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action func, RequestOptions options) @@ -66,11 +65,8 @@ namespace Discord.Rest return args; } - public static async Task KickAsync(IGuildUser user, BaseDiscordClient client, - string reason, RequestOptions options) - { - await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, reason, options).ConfigureAwait(false); - } + public static Task KickAsync(IGuildUser user, BaseDiscordClient client, string reason, RequestOptions options) + => client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, reason, options); public static async Task CreateDMChannelAsync(IUser user, BaseDiscordClient client, RequestOptions options) @@ -91,7 +87,7 @@ namespace Discord.Rest await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false); } - public static async Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options) + public static Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options) { if (span.TotalDays > 28) // As its double, an exact value of 28 can be accepted. throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot be more than 28 days from the current date."); @@ -101,16 +97,16 @@ namespace Discord.Rest { TimedOutUntil = DateTimeOffset.UtcNow.Add(span) }; - await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options); } - public static async Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options) + public static Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options) { var apiArgs = new API.Rest.ModifyGuildMemberParams() { TimedOutUntil = null }; - await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options); } } } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs index 5faa856a..385a6f3a 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs @@ -8,7 +8,7 @@ namespace Discord.Rest { internal static class WebhookHelper { - public static async Task ModifyAsync(IWebhook webhook, BaseDiscordClient client, + public static Task ModifyAsync(IWebhook webhook, BaseDiscordClient client, Action func, RequestOptions options) { var args = new WebhookProperties(); @@ -27,11 +27,10 @@ namespace Discord.Rest else if (args.ChannelId.IsSpecified) apiArgs.ChannelId = args.ChannelId.Value; - return await client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options).ConfigureAwait(false); - } - public static async Task DeleteAsync(IWebhook webhook, BaseDiscordClient client, RequestOptions options) - { - await client.ApiClient.DeleteWebhookAsync(webhook.Id, options).ConfigureAwait(false); + return client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options); } + + public static Task DeleteAsync(IWebhook webhook, BaseDiscordClient client, RequestOptions options) + => client.ApiClient.DeleteWebhookAsync(webhook.Id, options); } } diff --git a/src/Discord.Net.Rest/Net/DefaultRestClient.cs b/src/Discord.Net.Rest/Net/DefaultRestClient.cs index 46522a36..7142ad0e 100644 --- a/src/Discord.Net.Rest/Net/DefaultRestClient.cs +++ b/src/Discord.Net.Rest/Net/DefaultRestClient.cs @@ -97,7 +97,7 @@ namespace Discord.Net.Rest } /// Unsupported param type. - public async Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null, + public Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null, IEnumerable>> requestHeaders = null) { string uri = Path.Combine(_baseUrl, endpoint); @@ -162,7 +162,7 @@ namespace Discord.Net.Rest } restRequest.Content = content; - return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); + return SendInternalAsync(restRequest, cancelToken, headerOnly); } private async Task SendInternalAsync(HttpRequestMessage request, CancellationToken cancelToken, bool headerOnly) diff --git a/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs b/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs index 4915a5c3..3da8b3dc 100644 --- a/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs +++ b/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs @@ -99,7 +99,7 @@ namespace Discord.Net.Queue createdTokenSource?.Dispose(); } - internal async Task EnterGlobalAsync(int id, RestRequest request) + internal Task EnterGlobalAsync(int id, RestRequest request) { int millis = (int)Math.Ceiling((_waitUntil - DateTimeOffset.UtcNow).TotalMilliseconds); if (millis > 0) @@ -107,19 +107,23 @@ namespace Discord.Net.Queue #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Sleeping {millis} ms (Pre-emptive) [Global]"); #endif - await Task.Delay(millis).ConfigureAwait(false); + return Task.Delay(millis); } + + return Task.CompletedTask; } + internal void PauseGlobal(RateLimitInfo info) { _waitUntil = DateTimeOffset.UtcNow.AddMilliseconds(info.RetryAfter.Value + (info.Lag?.TotalMilliseconds ?? 0.0)); } - internal async Task EnterGlobalAsync(int id, WebSocketRequest request) + + internal Task EnterGlobalAsync(int id, WebSocketRequest request) { //If this is a global request (unbucketed), it'll be dealt in EnterAsync var requestBucket = GatewayBucket.Get(request.Options.BucketId); if (requestBucket.Type == GatewayBucketType.Unbucketed) - return; + return Task.CompletedTask; //It's not a global request, so need to remove one from global (per-session) var globalBucketType = GatewayBucket.Get(GatewayBucketType.Unbucketed); @@ -127,7 +131,7 @@ namespace Discord.Net.Queue options.BucketId = globalBucketType.Id; var globalRequest = new WebSocketRequest(null, null, false, false, options); var globalBucket = GetOrCreateBucket(options, globalRequest); - await globalBucket.TriggerAsync(id, globalRequest); + return globalBucket.TriggerAsync(id, globalRequest); } private RequestBucket GetOrCreateBucket(RequestOptions options, IRequest request) @@ -141,10 +145,9 @@ namespace Discord.Net.Queue } return (RequestBucket)obj; } - internal async Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint) - { - await RateLimitTriggered(bucketId, info, endpoint).ConfigureAwait(false); - } + internal Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint) + => RateLimitTriggered(bucketId, info, endpoint); + internal (RequestBucket, BucketId) UpdateBucketHash(BucketId id, string discordHash) { if (!id.IsHashBucket) diff --git a/src/Discord.Net.Rest/Net/Queue/Requests/JsonRestRequest.cs b/src/Discord.Net.Rest/Net/Queue/Requests/JsonRestRequest.cs index d0a44903..ff321870 100644 --- a/src/Discord.Net.Rest/Net/Queue/Requests/JsonRestRequest.cs +++ b/src/Discord.Net.Rest/Net/Queue/Requests/JsonRestRequest.cs @@ -13,9 +13,7 @@ namespace Discord.Net.Queue Json = json; } - public override async Task SendAsync() - { - return await Client.SendAsync(Method, Endpoint, Json, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason).ConfigureAwait(false); - } + public override Task SendAsync() + => Client.SendAsync(Method, Endpoint, Json, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason); } } diff --git a/src/Discord.Net.Rest/Net/Queue/Requests/MultipartRestRequest.cs b/src/Discord.Net.Rest/Net/Queue/Requests/MultipartRestRequest.cs index 09d558f1..b26f343f 100644 --- a/src/Discord.Net.Rest/Net/Queue/Requests/MultipartRestRequest.cs +++ b/src/Discord.Net.Rest/Net/Queue/Requests/MultipartRestRequest.cs @@ -14,9 +14,7 @@ namespace Discord.Net.Queue MultipartParams = multipartParams; } - public override async Task SendAsync() - { - return await Client.SendAsync(Method, Endpoint, MultipartParams, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason).ConfigureAwait(false); - } + public override Task SendAsync() + => Client.SendAsync(Method, Endpoint, MultipartParams, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason); } } diff --git a/src/Discord.Net.Rest/Net/Queue/Requests/RestRequest.cs b/src/Discord.Net.Rest/Net/Queue/Requests/RestRequest.cs index e5cab831..3240360f 100644 --- a/src/Discord.Net.Rest/Net/Queue/Requests/RestRequest.cs +++ b/src/Discord.Net.Rest/Net/Queue/Requests/RestRequest.cs @@ -29,9 +29,7 @@ namespace Discord.Net.Queue Promise = new TaskCompletionSource(); } - public virtual async Task SendAsync() - { - return await Client.SendAsync(Method, Endpoint, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason, Options.RequestHeaders).ConfigureAwait(false); - } + public virtual Task SendAsync() + => Client.SendAsync(Method, Endpoint, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason, Options.RequestHeaders); } } diff --git a/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs b/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs index ebebd7be..ab523ea3 100644 --- a/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs +++ b/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs @@ -30,9 +30,7 @@ namespace Discord.Net.Queue Promise = new TaskCompletionSource(); } - public async Task SendAsync() - { - await Client.SendAsync(Data, 0, Data.Length, IsText).ConfigureAwait(false); - } + public Task SendAsync() + => Client.SendAsync(Data, 0, Data.Length, IsText); } } diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index 1bd4d434..e1379fdd 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -95,13 +95,13 @@ namespace Discord.Audio UdpLatencyUpdated += async (old, val) => await _audioLogger.DebugAsync($"UDP Latency = {val} ms").ConfigureAwait(false); } - internal async Task StartAsync(string url, ulong userId, string sessionId, string token) + internal Task StartAsync(string url, ulong userId, string sessionId, string token) { _url = url; _userId = userId; _sessionId = sessionId; _token = token; - await _connection.StartAsync().ConfigureAwait(false); + return _connection.StartAsync(); } public IReadOnlyDictionary GetStreams() @@ -109,10 +109,8 @@ namespace Discord.Audio return _streams.ToDictionary(pair => pair.Key, pair => pair.Value.Reader); } - public async Task StopAsync() - { - await _connection.StopAsync().ConfigureAwait(false); - } + public Task StopAsync() + => _connection.StopAsync(); private async Task OnConnectingAsync() { diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs index 33657490..e900c10b 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs @@ -47,14 +47,11 @@ namespace Discord.Audio.Streams return _next.WriteAsync(_buffer, 0, count, cancelToken); } - public override async Task FlushAsync(CancellationToken cancelToken) - { - await _next.FlushAsync(cancelToken).ConfigureAwait(false); - } - public override async Task ClearAsync(CancellationToken cancelToken) - { - await _next.ClearAsync(cancelToken).ConfigureAwait(false); - } + public override Task FlushAsync(CancellationToken cancelToken) + => _next.FlushAsync(cancelToken); + + public override Task ClearAsync(CancellationToken cancelToken) + => _next.ClearAsync(cancelToken); protected override void Dispose(bool disposing) { diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs index cabd8487..259ece63 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs @@ -103,14 +103,11 @@ namespace Discord.Audio.Streams await base.FlushAsync(cancelToken).ConfigureAwait(false); }*/ - public override async Task FlushAsync(CancellationToken cancelToken) - { - await _next.FlushAsync(cancelToken).ConfigureAwait(false); - } - public override async Task ClearAsync(CancellationToken cancelToken) - { - await _next.ClearAsync(cancelToken).ConfigureAwait(false); - } + public override Task FlushAsync(CancellationToken cancelToken) + => _next.FlushAsync(cancelToken); + + public override Task ClearAsync(CancellationToken cancelToken) + => _next.ClearAsync(cancelToken); protected override void Dispose(bool disposing) { diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OutputStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OutputStream.cs index b5ba7541..91fe6315 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OutputStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OutputStream.cs @@ -15,10 +15,10 @@ namespace Discord.Audio.Streams } public override void WriteHeader(ushort seq, uint timestamp, bool missed) { } //Ignore - public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) { cancelToken.ThrowIfCancellationRequested(); - await _client.SendAsync(buffer, offset, count).ConfigureAwait(false); + return _client.SendAsync(buffer, offset, count); } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs index 40925b13..23317467 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs @@ -23,7 +23,7 @@ namespace Discord.Audio.Streams /// The token has had cancellation requested. /// The associated has been disposed. - public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) { cancelToken.ThrowIfCancellationRequested(); @@ -38,7 +38,7 @@ namespace Discord.Audio.Streams (buffer[offset + 7] << 0)); _next.WriteHeader(seq, timestamp, false); - await _next.WriteAsync(buffer, offset + headerSize, count - headerSize, cancelToken).ConfigureAwait(false); + return _next.WriteAsync(buffer, offset + headerSize, count - headerSize, cancelToken); } public static bool TryReadSsrc(byte[] buffer, int offset, out uint ssrc) diff --git a/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs index 48215f5e..6bf4e739 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs @@ -38,7 +38,7 @@ namespace Discord.Audio.Streams _nextSeq = seq; _nextTimestamp = timestamp; } - public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) { cancelToken.ThrowIfCancellationRequested(); if (!_hasHeader) @@ -58,17 +58,14 @@ namespace Discord.Audio.Streams Buffer.BlockCopy(buffer, offset, _buffer, 12, count); _next.WriteHeader(_nextSeq, _nextTimestamp, false); - await _next.WriteAsync(_buffer, 0, count + 12).ConfigureAwait(false); + return _next.WriteAsync(_buffer, 0, count + 12); } - public override async Task FlushAsync(CancellationToken cancelToken) - { - await _next.FlushAsync(cancelToken).ConfigureAwait(false); - } - public override async Task ClearAsync(CancellationToken cancelToken) - { - await _next.ClearAsync(cancelToken).ConfigureAwait(false); - } + public override Task FlushAsync(CancellationToken cancelToken) + => _next.FlushAsync(cancelToken); + + public override Task ClearAsync(CancellationToken cancelToken) + => _next.ClearAsync(cancelToken); protected override void Dispose(bool disposing) { diff --git a/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs index 40cd6864..f343f0cc 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs @@ -24,26 +24,23 @@ namespace Discord.Audio.Streams _nonce = new byte[24]; } - public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken) { cancelToken.ThrowIfCancellationRequested(); if (_client.SecretKey == null) - return; + return Task.CompletedTask; Buffer.BlockCopy(buffer, 0, _nonce, 0, 12); //Copy RTP header to nonce count = SecretBox.Decrypt(buffer, offset + 12, count - 12, buffer, offset + 12, _nonce, _client.SecretKey); - await _next.WriteAsync(buffer, 0, count + 12, cancelToken).ConfigureAwait(false); + return _next.WriteAsync(buffer, 0, count + 12, cancelToken); } - public override async Task FlushAsync(CancellationToken cancelToken) - { - await _next.FlushAsync(cancelToken).ConfigureAwait(false); - } - public override async Task ClearAsync(CancellationToken cancelToken) - { - await _next.ClearAsync(cancelToken).ConfigureAwait(false); - } + public override Task FlushAsync(CancellationToken cancelToken) + => _next.FlushAsync(cancelToken); + + public override Task ClearAsync(CancellationToken cancelToken) + => _next.ClearAsync(cancelToken); protected override void Dispose(bool disposing) { diff --git a/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs index 268dfcb4..30799e82 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs @@ -52,14 +52,11 @@ namespace Discord.Audio.Streams await _next.WriteAsync(buffer, 0, count + 12, cancelToken).ConfigureAwait(false); } - public override async Task FlushAsync(CancellationToken cancelToken) - { - await _next.FlushAsync(cancelToken).ConfigureAwait(false); - } - public override async Task ClearAsync(CancellationToken cancelToken) - { - await _next.ClearAsync(cancelToken).ConfigureAwait(false); - } + public override Task FlushAsync(CancellationToken cancelToken) + => _next.FlushAsync(cancelToken); + + public override Task ClearAsync(CancellationToken cancelToken) + => _next.ClearAsync(cancelToken); protected override void Dispose(bool disposing) { diff --git a/src/Discord.Net.WebSocket/ConnectionManager.cs b/src/Discord.Net.WebSocket/ConnectionManager.cs index 44cdfa93..b7152ac1 100644 --- a/src/Discord.Net.WebSocket/ConnectionManager.cs +++ b/src/Discord.Net.WebSocket/ConnectionManager.cs @@ -177,14 +177,11 @@ namespace Discord await _logger.InfoAsync("Disconnected").ConfigureAwait(false); } - public async Task CompleteAsync() - { - await _readyPromise.TrySetResultAsync(true).ConfigureAwait(false); - } - public async Task WaitAsync() - { - await _readyPromise.Task.ConfigureAwait(false); - } + public Task CompleteAsync() + => _readyPromise.TrySetResultAsync(true); + + public Task WaitAsync() + => _readyPromise.Task; public void Cancel() { diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index d7145215..155d1fb1 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -110,10 +110,10 @@ namespace Discord.WebSocket => new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost, useSystemClock: config.UseSystemClock, defaultRatelimitCallback: config.DefaultRatelimitCallback); - internal async Task AcquireIdentifyLockAsync(int shardId, CancellationToken token) + internal Task AcquireIdentifyLockAsync(int shardId, CancellationToken token) { int semaphoreIdx = shardId % _baseConfig.IdentifyMaxConcurrency; - await _identifySemaphores[semaphoreIdx].WaitAsync(token).ConfigureAwait(false); + return _identifySemaphores[semaphoreIdx].WaitAsync(token); } internal void ReleaseIdentifyLock() @@ -198,11 +198,12 @@ namespace Discord.WebSocket } /// - public override async Task StartAsync() - => await Task.WhenAll(_shards.Select(x => x.StartAsync())).ConfigureAwait(false); + public override Task StartAsync() + => Task.WhenAll(_shards.Select(x => x.StartAsync())); + /// - public override async Task StopAsync() - => await Task.WhenAll(_shards.Select(x => x.StopAsync())).ConfigureAwait(false); + public override Task StopAsync() + => Task.WhenAll(_shards.Select(x => x.StopAsync())); public DiscordSocketClient GetShard(int id) { @@ -220,8 +221,8 @@ namespace Discord.WebSocket => GetShardFor(guild?.Id ?? 0); /// - public override async Task GetApplicationInfoAsync(RequestOptions options = null) - => await _shards[0].GetApplicationInfoAsync(options).ConfigureAwait(false); + public override Task GetApplicationInfoAsync(RequestOptions options = null) + => _shards[0].GetApplicationInfoAsync(options); /// public override SocketGuild GetGuild(ulong id) @@ -355,16 +356,12 @@ namespace Discord.WebSocket } /// - public override async ValueTask> GetVoiceRegionsAsync(RequestOptions options = null) - { - return await _shards[0].GetVoiceRegionsAsync().ConfigureAwait(false); - } + public override ValueTask> GetVoiceRegionsAsync(RequestOptions options = null) + => _shards[0].GetVoiceRegionsAsync(); /// - public override async ValueTask GetVoiceRegionAsync(string id, RequestOptions options = null) - { - return await _shards[0].GetVoiceRegionAsync(id, options).ConfigureAwait(false); - } + public override ValueTask GetVoiceRegionAsync(string id, RequestOptions options = null) + => _shards[0].GetVoiceRegionAsync(id, options); /// /// is @@ -396,14 +393,14 @@ namespace Discord.WebSocket await _shards[i].SetStatusAsync(status).ConfigureAwait(false); } /// - public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing) + public override Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing) { IActivity activity = null; if (!string.IsNullOrEmpty(streamUrl)) activity = new StreamingGame(name, streamUrl); else if (!string.IsNullOrEmpty(name)) activity = new Game(name, type); - await SetActivityAsync(activity).ConfigureAwait(false); + return SetActivityAsync(activity); } /// public override async Task SetActivityAsync(IActivity activity) diff --git a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs index ab12ab7b..f33199ba 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs @@ -317,7 +317,7 @@ namespace Discord.API #endif } - public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null) + public Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var props = new Dictionary @@ -350,9 +350,10 @@ namespace Discord.API }; } - await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.Identify, msg, options: options); } - public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null) + + public Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var msg = new ResumeParams() @@ -361,14 +362,16 @@ namespace Discord.API SessionId = sessionId, Sequence = lastSeq }; - await SendGatewayAsync(GatewayOpCode.Resume, msg, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.Resume, msg, options: options); } - public async Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null) + + public Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options); } - public async Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null) + + public Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var args = new PresenceUpdateParams @@ -379,14 +382,16 @@ namespace Discord.API Activities = new object[] { game } }; options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id; - await SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options); } - public async Task SendRequestMembersAsync(IEnumerable guildIds, RequestOptions options = null) + + public Task SendRequestMembersAsync(IEnumerable guildIds, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options); } - public async Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null) + + public Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null) { var payload = new VoiceStateUpdateParams { @@ -396,17 +401,19 @@ namespace Discord.API SelfMute = selfMute }; options = RequestOptions.CreateOrClone(options); - await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options); } - public async Task SendVoiceStateUpdateAsync(VoiceStateUpdateParams payload, RequestOptions options = null) + + public Task SendVoiceStateUpdateAsync(VoiceStateUpdateParams payload, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options); } - public async Task SendGuildSyncAsync(IEnumerable guildIds, RequestOptions options = null) + + public Task SendGuildSyncAsync(IEnumerable guildIds, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - await SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options).ConfigureAwait(false); + return SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options); } #endregion } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index d96ca549..9641145b 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -284,11 +284,12 @@ namespace Discord.WebSocket } /// - public override async Task StartAsync() - => await _connection.StartAsync().ConfigureAwait(false); + public override Task StartAsync() + => _connection.StartAsync(); + /// - public override async Task StopAsync() - => await _connection.StopAsync().ConfigureAwait(false); + public override Task StopAsync() + => _connection.StopAsync(); private async Task OnConnectingAsync() { @@ -642,16 +643,18 @@ namespace Discord.WebSocket } /// - public override async Task DownloadUsersAsync(IEnumerable guilds) + public override Task DownloadUsersAsync(IEnumerable guilds) { if (ConnectionState == ConnectionState.Connected) { EnsureGatewayIntent(GatewayIntents.GuildMembers); //Race condition leads to guilds being requested twice, probably okay - await ProcessUserDownloadsAsync(guilds.Select(x => GetGuild(x.Id)).Where(x => x != null)).ConfigureAwait(false); + return ProcessUserDownloadsAsync(guilds.Select(x => GetGuild(x.Id)).Where(x => x != null)); } + return Task.CompletedTask; } + private async Task ProcessUserDownloadsAsync(IEnumerable guilds) { var cachedGuilds = guilds.ToImmutableArray(); @@ -689,15 +692,16 @@ namespace Discord.WebSocket /// await client.SetStatusAsync(UserStatus.DoNotDisturb); /// /// - public override async Task SetStatusAsync(UserStatus status) + public override Task SetStatusAsync(UserStatus status) { Status = status; if (status == UserStatus.AFK) _statusSince = DateTimeOffset.UtcNow; else _statusSince = null; - await SendStatusAsync().ConfigureAwait(false); + return SendStatusAsync(); } + /// /// /// @@ -713,7 +717,7 @@ namespace Discord.WebSocket /// /// /// - public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing) + public override Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing) { if (!string.IsNullOrEmpty(streamUrl)) Activity = new StreamingGame(name, streamUrl); @@ -721,27 +725,27 @@ namespace Discord.WebSocket Activity = new Game(name, type); else Activity = null; - await SendStatusAsync().ConfigureAwait(false); + return SendStatusAsync(); } /// - public override async Task SetActivityAsync(IActivity activity) + public override Task SetActivityAsync(IActivity activity) { Activity = activity; - await SendStatusAsync().ConfigureAwait(false); + return SendStatusAsync(); } /// - public override async Task SetCustomStatusAsync(string status) + public override Task SetCustomStatusAsync(string status) { var statusGame = new CustomStatusGame(status); - await SetActivityAsync(statusGame); + return SetActivityAsync(statusGame); } - private async Task SendStatusAsync() + private Task SendStatusAsync() { if (CurrentUser == null) - return; + return Task.CompletedTask; var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null; @@ -749,11 +753,11 @@ namespace Discord.WebSocket var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null); - await ApiClient.SendPresenceUpdateAsync( + return ApiClient.SendPresenceUpdateAsync( status: presence.Item1, isAFK: presence.Item2, since: presence.Item3, - game: presence.Item4).ConfigureAwait(false); + game: presence.Item4); } private (UserStatus, bool, long?, GameModel)? BuildCurrentStatus() @@ -3268,11 +3272,14 @@ namespace Discord.WebSocket await logger.ErrorAsync("GuildDownloader Errored", ex).ConfigureAwait(false); } } - private async Task SyncGuildsAsync() + + private Task SyncGuildsAsync() { var guildIds = Guilds.Where(x => !x.IsSynced).Select(x => x.Id).ToImmutableArray(); if (guildIds.Length > 0) - await ApiClient.SendGuildSyncAsync(guildIds).ConfigureAwait(false); + return ApiClient.SendGuildSyncAsync(guildIds); + + return Task.CompletedTask; } internal SocketGuild AddGuild(ExtendedGuild model, ClientState state) @@ -3334,83 +3341,106 @@ namespace Discord.WebSocket internal bool HasGatewayIntent(GatewayIntents intents) => _gatewayIntents.HasFlag(intents); - private async Task GuildAvailableAsync(SocketGuild guild) + private Task GuildAvailableAsync(SocketGuild guild) { if (!guild.IsConnected) { guild.IsConnected = true; - await TimedInvokeAsync(_guildAvailableEvent, nameof(GuildAvailable), guild).ConfigureAwait(false); + return TimedInvokeAsync(_guildAvailableEvent, nameof(GuildAvailable), guild); } + + return Task.CompletedTask; } - private async Task GuildUnavailableAsync(SocketGuild guild) + + private Task GuildUnavailableAsync(SocketGuild guild) { if (guild.IsConnected) { guild.IsConnected = false; - await TimedInvokeAsync(_guildUnavailableEvent, nameof(GuildUnavailable), guild).ConfigureAwait(false); + return TimedInvokeAsync(_guildUnavailableEvent, nameof(GuildUnavailable), guild); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name) + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, eventHandler.InvokeAsync).ConfigureAwait(false); + return TimeoutWrap(name, eventHandler.InvokeAsync); else - await eventHandler.InvokeAsync().ConfigureAwait(false); + return eventHandler.InvokeAsync(); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T arg) + + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T arg) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg)).ConfigureAwait(false); + return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg)); else - await eventHandler.InvokeAsync(arg).ConfigureAwait(false); + return eventHandler.InvokeAsync(arg); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2) + + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2)).ConfigureAwait(false); + return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2)); else - await eventHandler.InvokeAsync(arg1, arg2).ConfigureAwait(false); + return eventHandler.InvokeAsync(arg1, arg2); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3) + + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3)).ConfigureAwait(false); + return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3)); else - await eventHandler.InvokeAsync(arg1, arg2, arg3).ConfigureAwait(false); + return eventHandler.InvokeAsync(arg1, arg2, arg3); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4)).ConfigureAwait(false); + return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4)); else - await eventHandler.InvokeAsync(arg1, arg2, arg3, arg4).ConfigureAwait(false); + return eventHandler.InvokeAsync(arg1, arg2, arg3, arg4); } + + return Task.CompletedTask; } - private async Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + + private Task TimedInvokeAsync(AsyncEvent> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { if (eventHandler.HasSubscribers) { if (HandlerTimeout.HasValue) - await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5)).ConfigureAwait(false); + return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5)); else - await eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5).ConfigureAwait(false); + return eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5); } + + return Task.CompletedTask; } + private async Task TimeoutWrap(string name, Func action) { try @@ -3429,61 +3459,68 @@ namespace Discord.WebSocket } } - private async Task UnknownGlobalUserAsync(string evnt, ulong userId) + private Task UnknownGlobalUserAsync(string evnt, ulong userId) { string details = $"{evnt} User={userId}"; - await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown User ({details})."); } - private async Task UnknownChannelUserAsync(string evnt, ulong userId, ulong channelId) + + private Task UnknownChannelUserAsync(string evnt, ulong userId, ulong channelId) { string details = $"{evnt} User={userId} Channel={channelId}"; - await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown User ({details})."); } - private async Task UnknownGuildUserAsync(string evnt, ulong userId, ulong guildId) + + private Task UnknownGuildUserAsync(string evnt, ulong userId, ulong guildId) { string details = $"{evnt} User={userId} Guild={guildId}"; - await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown User ({details})."); } - private async Task IncompleteGuildUserAsync(string evnt, ulong userId, ulong guildId) + + private Task IncompleteGuildUserAsync(string evnt, ulong userId, ulong guildId) { string details = $"{evnt} User={userId} Guild={guildId}"; - await _gatewayLogger.DebugAsync($"User has not been downloaded ({details}).").ConfigureAwait(false); + return _gatewayLogger.DebugAsync($"User has not been downloaded ({details})."); } - private async Task UnknownChannelAsync(string evnt, ulong channelId) + + private Task UnknownChannelAsync(string evnt, ulong channelId) { string details = $"{evnt} Channel={channelId}"; - await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown Channel ({details})."); } - private async Task UnknownChannelAsync(string evnt, ulong channelId, ulong guildId) + + private Task UnknownChannelAsync(string evnt, ulong channelId, ulong guildId) { if (guildId == 0) { - await UnknownChannelAsync(evnt, channelId).ConfigureAwait(false); - return; + return UnknownChannelAsync(evnt, channelId); } string details = $"{evnt} Channel={channelId} Guild={guildId}"; - await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false); - } - private async Task UnknownRoleAsync(string evnt, ulong roleId, ulong guildId) - { - string details = $"{evnt} Role={roleId} Guild={guildId}"; - await _gatewayLogger.WarningAsync($"Unknown Role ({details}).").ConfigureAwait(false); - } - private async Task UnknownGuildAsync(string evnt, ulong guildId) - { - string details = $"{evnt} Guild={guildId}"; - await _gatewayLogger.WarningAsync($"Unknown Guild ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown Channel ({details})."); } - private async Task UnknownGuildEventAsync(string evnt, ulong eventId, ulong guildId) + private Task UnknownRoleAsync(string evnt, ulong roleId, ulong guildId) { - string details = $"{evnt} Event={eventId} Guild={guildId}"; - await _gatewayLogger.WarningAsync($"Unknown Guild Event ({details}).").ConfigureAwait(false); + string details = $"{evnt} Role={roleId} Guild={guildId}"; + return _gatewayLogger.WarningAsync($"Unknown Role ({details})."); } - private async Task UnsyncedGuildAsync(string evnt, ulong guildId) + + private Task UnknownGuildAsync(string evnt, ulong guildId) { string details = $"{evnt} Guild={guildId}"; - await _gatewayLogger.DebugAsync($"Unsynced Guild ({details}).").ConfigureAwait(false); + return _gatewayLogger.WarningAsync($"Unknown Guild ({details})."); + } + + private Task UnknownGuildEventAsync(string evnt, ulong eventId, ulong guildId) + { + string details = $"{evnt} Event={eventId} Guild={guildId}"; + return _gatewayLogger.WarningAsync($"Unknown Guild Event ({details})."); + } + + private Task UnsyncedGuildAsync(string evnt, ulong guildId) + { + string details = $"{evnt} Guild={guildId}"; + return _gatewayLogger.DebugAsync($"Unsynced Guild ({details})."); } internal int GetAudioId() => _nextAudioId++; @@ -3558,11 +3595,12 @@ namespace Discord.WebSocket => await BulkOverwriteGlobalApplicationCommandsAsync(properties, options); /// - async Task IDiscordClient.StartAsync() - => await StartAsync().ConfigureAwait(false); + Task IDiscordClient.StartAsync() + => StartAsync(); + /// - async Task IDiscordClient.StopAsync() - => await StopAsync().ConfigureAwait(false); + Task IDiscordClient.StopAsync() + => StopAsync(); #endregion } } diff --git a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs index 027822ea..31be80a3 100644 --- a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs @@ -55,7 +55,7 @@ namespace Discord.Audio GuildId = guildId; _connectionLock = new SemaphoreSlim(1, 1); _udp = udpSocketProvider(); - _udp.ReceivedDatagram += async (data, index, count) => + _udp.ReceivedDatagram += (data, index, count) => { if (index != 0 || count != data.Length) { @@ -63,7 +63,7 @@ namespace Discord.Audio Buffer.BlockCopy(data, index, newData, 0, count); data = newData; } - await _receivedPacketEvent.InvokeAsync(data).ConfigureAwait(false); + return _receivedPacketEvent.InvokeAsync(data); }; WebSocketClient = webSocketProvider(); @@ -83,10 +83,10 @@ namespace Discord.Audio } } }; - WebSocketClient.TextMessage += async text => + WebSocketClient.TextMessage += text => { var msg = JsonConvert.DeserializeObject(text); - await _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload).ConfigureAwait(false); + return _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload); }; WebSocketClient.Closed += async ex => { @@ -129,23 +129,23 @@ namespace Discord.Audio #endregion #region WebSocket - public async Task SendHeartbeatAsync(RequestOptions options = null) + public Task SendHeartbeatAsync(RequestOptions options = null) + => SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options); + + public Task SendIdentityAsync(ulong userId, string sessionId, string token) { - await SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options).ConfigureAwait(false); - } - public async Task SendIdentityAsync(ulong userId, string sessionId, string token) - { - await SendAsync(VoiceOpCode.Identify, new IdentifyParams + return SendAsync(VoiceOpCode.Identify, new IdentifyParams { GuildId = GuildId, UserId = userId, SessionId = sessionId, Token = token - }).ConfigureAwait(false); + }); } - public async Task SendSelectProtocol(string externalIp, int externalPort) + + public Task SendSelectProtocol(string externalIp, int externalPort) { - await SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams + return SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams { Protocol = "udp", Data = new UdpProtocolInfo @@ -154,15 +154,16 @@ namespace Discord.Audio Port = externalPort, Mode = Mode } - }).ConfigureAwait(false); + }); } - public async Task SendSetSpeaking(bool value) + + public Task SendSetSpeaking(bool value) { - await SendAsync(VoiceOpCode.Speaking, new SpeakingParams + return SendAsync(VoiceOpCode.Speaking, new SpeakingParams { IsSpeaking = value, Delay = 0 - }).ConfigureAwait(false); + }); } public async Task ConnectAsync(string url) @@ -174,6 +175,7 @@ namespace Discord.Audio } finally { _connectionLock.Release(); } } + private async Task ConnectInternalAsync(string url) { ConnectionState = ConnectionState.Connecting; diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index b86865bf..a5dc2051 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -259,13 +259,14 @@ namespace Discord.WebSocket #region IMessageChannel /// - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) + Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options).ConfigureAwait(false); + return GetMessageAsync(id, options); else - return GetCachedMessage(id); + return Task.FromResult((IMessage)GetCachedMessage(id)); } + /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) => mode == CacheMode.CacheOnly ? null : GetMessagesAsync(limit, options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index cc918fe9..517b7b03 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -330,12 +330,12 @@ namespace Discord.WebSocket #region IMessageChannel /// - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) + Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options).ConfigureAwait(false); + return GetMessageAsync(id, options); else - return GetCachedMessage(id); + return Task.FromResult((IMessage)GetCachedMessage(id)); } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 027b217d..92dd93d6 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -131,10 +131,8 @@ namespace Discord.WebSocket /// /// A task representing the asynchronous permission operation for adding the specified permissions to the channel. /// - public virtual async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) - { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options).ConfigureAwait(false); - } + public virtual Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) + => ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options); /// /// Adds or updates the permission overwrite for the given role. @@ -145,10 +143,9 @@ namespace Discord.WebSocket /// /// A task representing the asynchronous permission operation for adding the specified permissions to the channel. /// - public virtual async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) - { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options).ConfigureAwait(false); - } + public virtual Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) + => ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options); + /// /// Removes the permission overwrite for the given user, if one exists. /// @@ -157,10 +154,9 @@ namespace Discord.WebSocket /// /// A task representing the asynchronous operation for removing the specified permissions from the channel. /// - public virtual async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) - { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); - } + public virtual Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) + => ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options); + /// /// Removes the permission overwrite for the given role, if one exists. /// @@ -169,10 +165,8 @@ namespace Discord.WebSocket /// /// A task representing the asynchronous operation for removing the specified permissions from the channel. /// - public virtual async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) - { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); - } + public virtual Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) + => ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options); public new virtual SocketGuildUser GetUser(ulong id) => null; @@ -207,17 +201,20 @@ namespace Discord.WebSocket OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); /// - async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false); + Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) + => AddPermissionOverwriteAsync(role, permissions, options); + /// - async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false); + Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) + => AddPermissionOverwriteAsync(user, permissions, options); + /// - async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) - => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); + Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) + => RemovePermissionOverwriteAsync(role, options); + /// - async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) - => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); + Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) + => RemovePermissionOverwriteAsync(user, options); /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index d2c50a16..06560aff 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -413,12 +413,12 @@ namespace Discord.WebSocket #region IMessageChannel /// - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) + Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options).ConfigureAwait(false); + return GetMessageAsync(id, options); else - return GetCachedMessage(id); + return Task.FromResult((IMessage)GetCachedMessage(id)); } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index e0439880..4cfe1801 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -89,20 +89,17 @@ namespace Discord.WebSocket => ChannelHelper.ModifyAsync(this, Discord, func, options); /// - public async Task ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) - { - return await Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external).ConfigureAwait(false); - } + public Task ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) + => Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external); /// - public async Task DisconnectAsync() - => await Guild.DisconnectAudioAsync(); + public Task DisconnectAsync() + => Guild.DisconnectAudioAsync(); /// - public async Task ModifyAsync(Action func, RequestOptions options = null) - { - await Guild.ModifyAudioAsync(Id, func, options).ConfigureAwait(false); - } + public Task ModifyAsync(Action func, RequestOptions options = null) + => Guild.ModifyAudioAsync(Id, func, options); + /// public override SocketGuildUser GetUser(ulong id) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index f03bbed7..84c39d47 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -1307,10 +1307,9 @@ namespace Discord.WebSocket } /// - public async Task DownloadUsersAsync() - { - await Discord.DownloadUsersAsync(new[] { this }).ConfigureAwait(false); - } + public Task DownloadUsersAsync() + => Discord.DownloadUsersAsync(new[] { this }); + internal void CompleteDownloadUsers() { _downloaderPromise.TrySetResultAsync(true); @@ -1545,7 +1544,8 @@ namespace Discord.WebSocket /// /// The user to disconnect. /// A task that represents the asynchronous operation for disconnecting a user. - async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = null); + Task IGuild.DisconnectAsync(IGuildUser user) + => user.ModifyAsync(x => x.Channel = null); #endregion #region Stickers @@ -1850,7 +1850,7 @@ namespace Discord.WebSocket } } - private async Task ModifyAudioInternalAsync(ulong channelId, Action func, RequestOptions options) + private Task ModifyAudioInternalAsync(ulong channelId, Action func, RequestOptions options) { if (_voiceStateUpdateParams == null || _voiceStateUpdateParams.ChannelId != channelId) throw new InvalidOperationException("Cannot modify properties of not connected audio channel"); @@ -1863,7 +1863,7 @@ namespace Discord.WebSocket if (props.SelfMute.IsSpecified) _voiceStateUpdateParams.SelfMute = props.SelfMute.Value; - await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams, options).ConfigureAwait(false); + return Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams, options); } internal async Task FinishConnectAudio(string url, string token) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs index 23c6f144..25c48a79 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs @@ -305,7 +305,7 @@ namespace Discord.WebSocket } /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -338,11 +338,11 @@ namespace Discord.WebSocket if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -391,7 +391,7 @@ namespace Discord.WebSocket flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs index 9c2f25e7..9543b8af 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs @@ -302,7 +302,7 @@ namespace Discord.WebSocket } /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -335,11 +335,11 @@ namespace Discord.WebSocket if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -388,7 +388,7 @@ namespace Discord.WebSocket flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs index c9dd6555..2c6b27a0 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs @@ -234,7 +234,7 @@ namespace Discord.WebSocket } /// - public override async Task FollowupAsync( + public override Task FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, @@ -267,11 +267,11 @@ namespace Discord.WebSocket if (ephemeral) args.Flags = MessageFlags.Ephemeral; - return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); + return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); } /// - public override async Task FollowupWithFilesAsync( + public override Task FollowupWithFilesAsync( IEnumerable attachments, string text = null, Embed[] embeds = null, @@ -320,7 +320,7 @@ namespace Discord.WebSocket flags |= MessageFlags.Ephemeral; var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; - return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs index 596820e2..0a780660 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs @@ -228,14 +228,14 @@ namespace Discord.WebSocket /// /// This operation may only be called on a channel. - public async Task CrosspostAsync(RequestOptions options = null) + public Task CrosspostAsync(RequestOptions options = null) { if (!(Channel is INewsChannel)) { throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); } - await MessageHelper.CrosspostAsync(this, Discord, options); + return MessageHelper.CrosspostAsync(this, Discord, options); } private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; diff --git a/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs b/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs index 4068eaa6..91bb3378 100644 --- a/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs +++ b/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs @@ -116,7 +116,7 @@ namespace Discord.Net.Udp _cancelToken = _cancelTokenSource.Token; } - public async Task SendAsync(byte[] data, int index, int count) + public Task SendAsync(byte[] data, int index, int count) { if (index != 0) //Should never happen? { @@ -124,7 +124,7 @@ namespace Discord.Net.Udp Buffer.BlockCopy(data, index, newData, 0, count); data = newData; } - await _udp.SendAsync(data, count, _destination).ConfigureAwait(false); + return _udp.SendAsync(data, count, _destination); } private async Task RunAsync(CancellationToken cancelToken) diff --git a/src/Discord.Net.Webhook/WebhookClientHelper.cs b/src/Discord.Net.Webhook/WebhookClientHelper.cs index 373c6f42..715e45c4 100644 --- a/src/Discord.Net.Webhook/WebhookClientHelper.cs +++ b/src/Discord.Net.Webhook/WebhookClientHelper.cs @@ -56,7 +56,7 @@ namespace Discord.Webhook return model.Id; } - public static async Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId, + public static Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId, Action func, RequestOptions options, ulong? threadId) { var args = new WebhookMessageProperties(); @@ -104,8 +104,7 @@ namespace Discord.Webhook Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, }; - await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId) - .ConfigureAwait(false); + return client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId); } else { @@ -124,15 +123,12 @@ namespace Discord.Webhook MessageComponents = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, }; - await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId) - .ConfigureAwait(false); + return client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId); } } - public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options, ulong? threadId) - { - await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options, threadId).ConfigureAwait(false); - } + public static Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options, ulong? threadId) + => client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options, threadId); public static async Task SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, @@ -206,7 +202,7 @@ namespace Discord.Webhook return msg.Id; } - public static async Task ModifyAsync(DiscordWebhookClient client, Action func, RequestOptions options) + public static Task ModifyAsync(DiscordWebhookClient client, Action func, RequestOptions options) { var args = new WebhookProperties(); func(args); @@ -219,12 +215,10 @@ namespace Discord.Webhook if (!apiArgs.Avatar.IsSpecified && client.Webhook.AvatarId != null) apiArgs.Avatar = new ImageModel(client.Webhook.AvatarId); - return await client.ApiClient.ModifyWebhookAsync(client.Webhook.Id, apiArgs, options).ConfigureAwait(false); + return client.ApiClient.ModifyWebhookAsync(client.Webhook.Id, apiArgs, options); } - public static async Task DeleteAsync(DiscordWebhookClient client, RequestOptions options) - { - await client.ApiClient.DeleteWebhookAsync(client.Webhook.Id, options).ConfigureAwait(false); - } + public static Task DeleteAsync(DiscordWebhookClient client, RequestOptions options) + => client.ApiClient.DeleteWebhookAsync(client.Webhook.Id, options); } }