diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 45535746d..52929ae0a 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -344,11 +344,11 @@ namespace Discord.Rest } /// Message content is too long, length must be less or equal to . - public static Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, + public static async Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, bool isSpoiler, Embed[] embeds) { - using var file = new FileAttachment(stream, filename, isSpoiler: isSpoiler); - return SendFileAsync(channel, client, file, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + using (var file = new FileAttachment(stream, filename, isSpoiler: isSpoiler)) + return await SendFileAsync(channel, client, file, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds).ConfigureAwait(false); } /// Message content is too long, length must be less or equal to . diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs index db4ff1e0f..251a7cc28 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs @@ -183,7 +183,7 @@ namespace Discord.Rest } /// - public override Task FollowupWithFileAsync( + public override async Task FollowupWithFileAsync( Stream fileStream, string fileName, string text = null, @@ -198,18 +198,15 @@ namespace Discord.Rest if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); - embeds ??= Array.Empty(); - if (embed != null) - embeds = new[] { embed }.Concat(embeds).ToArray(); - Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data"); Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); - return FollowupWithFileAsync(new FileAttachment(fileStream, fileName), text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + using(var file = new FileAttachment(fileStream, fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); } /// - public override Task FollowupWithFileAsync( + public override async Task FollowupWithFileAsync( string filePath, string fileName = null, string text = null, @@ -226,7 +223,8 @@ namespace Discord.Rest fileName ??= Path.GetFileName(filePath); Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); - return FollowupWithFileAsync(new FileAttachment(File.OpenRead(filePath), fileName), text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + using (var file = new FileAttachment(File.OpenRead(filePath), fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs index 22d3f5b0b..8d234169c 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs @@ -275,7 +275,7 @@ namespace Discord.Rest } /// - public override Task FollowupWithFileAsync( + public override async Task FollowupWithFileAsync( Stream fileStream, string fileName, string text = null, @@ -290,18 +290,15 @@ namespace Discord.Rest if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); - embeds ??= Array.Empty(); - if (embed != null) - embeds = new[] { embed }.Concat(embeds).ToArray(); - Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data"); Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); - return FollowupWithFileAsync(new FileAttachment(fileStream, fileName), text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + using(var file = new FileAttachment(fileStream, fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); } /// - public override Task FollowupWithFileAsync( + public override async Task FollowupWithFileAsync( string filePath, string fileName = null, string text = null, @@ -318,7 +315,8 @@ namespace Discord.Rest fileName ??= Path.GetFileName(filePath); Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); - return FollowupWithFileAsync(new FileAttachment(File.OpenRead(filePath), fileName), text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + using(var file = new FileAttachment(File.OpenRead(filePath), fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); } ///