Search code examples
c#imagediscord

How do I add an image for a Discord bot in c#?


This is what I think that should work

I'm doing a bot for discord and I'm new to this, still trying to understand basics. I would like to add an image with out any message attached, how do i do this?

public class Command : ModuleBase<SocketCommandContext>
{
    [Command("Image")]
    public async Task ReplyImage()
    {
        await ReplyAsync("image.url");
    }
}

Solution

  • You must embed the image
    example :

    public class Command : ModuleBase<SocketCommandContext>
    {
        public async Task ReplyImage()
        {
            var embed = new EmbedBuilder();
            embed.WithImageUrl("image.url");
            await ReplyAsync("", false, embed.Build());
        }
    }
    

    Tips : ReplyAsync method is a part of the ModuleBase class from the Discord.Net library. You must add it by install Discord.Net from NuGet packages