0

I want my bot to send an image from given url with caption got from String(), but with SendFileAsync() it totally doesn't work. Is there another method for sending images from internet or I just screwed up something in here?

public class Task : ModuleBase
        {
            public Task()
            {
                Thread.Sleep(6000);
                IReadOnlyCollection<SocketGuild> guilds = CommandHandler._discord.Guilds;
                foreach (var guild in guilds)
                {
                    JobManager.AddJob(() => CommandHandler._discord.GetGuild(guild.Id).DefaultChannel.SendFileAsync("HERE_GOES_URL", String()), (s) => s.ToRunEvery(5).Seconds());
                }
            }
        }
        static void Initializer()
        {
            JobManager.Initialize(new MyRegistry());
        }
Call_me_Q
  • 5
  • 3

1 Answers1

1

To use SendFileAsync, you need to have the file locally. If you want to send a URL without downloading, just use SendMessageAsync. Discord will preview the image from the URL (unless the user disabled that manually).

Otherwise, this would help:

using System.Net;
using System.IO;
...
byte[] buffer = (new WebClient().DownloadData("myurl"));
using (MemoryStream ms = new MemoryStream(buffer))
{
   await SendFileAsync(ms, ...);
}

Wrapping this to a function is what I'd recommend.

If you are still convinced about not dealing with downloads, check out EmbedBuilder.

Notes not related to your question

Niha
  • 26
  • 2