Skip to content

Commit 2ea5bf1

Browse files
committed
attempt to fix discord file sending
1 parent 8326578 commit 2ea5bf1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Tools/BiblioTech/Options/CommandContext.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ await Command.ModifyOriginalResponseAsync(m =>
5151

5252
public async Task SendFile(string fileContent)
5353
{
54-
using var stream = new MemoryStream();
55-
using var writer = new StreamWriter(stream);
54+
var stream = new MemoryStream();
55+
var writer = new StreamWriter(stream);
5656
writer.Write(fileContent);
57-
stream.Position = 0;
5857

5958
await Command.RespondWithFileAsync(stream, "CheckFile.txt", ephemeral: true);
59+
60+
// Detached task for cleaning up the stream resources.
61+
_ = Task.Run(() =>
62+
{
63+
Thread.Sleep(TimeSpan.FromSeconds(30));
64+
writer.Dispose();
65+
stream.Dispose();
66+
});
6067
}
6168

6269
private string FormatChunk(string[] chunk)

0 commit comments

Comments
 (0)