From ad20e03a98d363a9cb5a7d2398ba268997658edf Mon Sep 17 00:00:00 2001
From: Quin Lynch <49576606+quinchs@users.noreply.github.com>
Date: Fri, 24 Dec 2021 10:38:11 -0400
Subject: [PATCH] Fixed file being disposed on upload (#1995)
---
.../Entities/Channels/ChannelHelper.cs | 6 +++---
.../Interactions/CommandBase/RestCommandBase.cs | 14 ++++++--------
.../MessageComponents/RestMessageComponent.cs | 14 ++++++--------
3 files changed, 15 insertions(+), 19 deletions(-)
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