From 2ea5bf1c5d8127ae320b5badd817265bb429ac1a Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 10 Apr 2025 17:49:26 +0200 Subject: [PATCH] attempt to fix discord file sending --- Tools/BiblioTech/Options/CommandContext.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Tools/BiblioTech/Options/CommandContext.cs b/Tools/BiblioTech/Options/CommandContext.cs index 884ef8b7..8f350c89 100644 --- a/Tools/BiblioTech/Options/CommandContext.cs +++ b/Tools/BiblioTech/Options/CommandContext.cs @@ -51,12 +51,19 @@ namespace BiblioTech.Options public async Task SendFile(string fileContent) { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); + var stream = new MemoryStream(); + var writer = new StreamWriter(stream); writer.Write(fileContent); - stream.Position = 0; await Command.RespondWithFileAsync(stream, "CheckFile.txt", ephemeral: true); + + // Detached task for cleaning up the stream resources. + _ = Task.Run(() => + { + Thread.Sleep(TimeSpan.FromSeconds(30)); + writer.Dispose(); + stream.Dispose(); + }); } private string FormatChunk(string[] chunk)