@@ -344,11 +344,11 @@ namespace Discord.Rest | |||
} | |||
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
public static Task<RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client, | |||
public static async Task<RestUserMessage> 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); | |||
} | |||
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
@@ -183,7 +183,7 @@ namespace Discord.Rest | |||
} | |||
/// <inheritdoc/> | |||
public override Task<RestFollowupMessage> FollowupWithFileAsync( | |||
public override async Task<RestFollowupMessage> 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<Embed>(); | |||
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); | |||
} | |||
/// <inheritdoc/> | |||
public override Task<RestFollowupMessage> FollowupWithFileAsync( | |||
public override async Task<RestFollowupMessage> 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); | |||
} | |||
/// <inheritdoc/> | |||
@@ -275,7 +275,7 @@ namespace Discord.Rest | |||
} | |||
/// <inheritdoc/> | |||
public override Task<RestFollowupMessage> FollowupWithFileAsync( | |||
public override async Task<RestFollowupMessage> 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<Embed>(); | |||
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); | |||
} | |||
/// <inheritdoc/> | |||
public override Task<RestFollowupMessage> FollowupWithFileAsync( | |||
public override async Task<RestFollowupMessage> 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); | |||
} | |||
/// <inheritdoc/> | |||