Answer the question
In order to leave comments, you need to log in
Discord.NET Bot completely ignores it when calling IMessageChannel.SendFileAsync. What to do?
I'm making a bot for my video game Discord server. One of its tasks is to "Approve" a user's post, which is created as a message of the format "Text" + Attached .mp3 file, by sending a copy of this message to a dedicated channel. For this I use the following code:
[Command("approve")]
public async Task Approve([Remainder] ulong id)
{
var sourceMsg = await Context.Channel.GetMessageAsync(id);
if (sourceMsg == null)
return;
var targetChannel = _client.GetChannel(ulong.Parse(_config["rankedSongsId"])) as IMessageChannel;
if (sourceMsg.Attachments.Count > 0)
{
var httpClient = new HttpClient();
var file = await httpClient.GetByteArrayAsync(sourceMsg.Attachments.ElementAt(0).Url).ConfigureAwait(true);
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(file))
{
var fileAtt = new FileAttachment(stream, sourceMsg.Attachments.ElementAt(0).Filename);
await targetChannel.SendFileAsync(fileAtt, text: sourceMsg.Content);
}
return;
}
await Context.Channel.SendMessageAsync("Can not approve offer without attached songfile").ConfigureAwait(true);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question