C# Discord Bot - Upload Local Image

IAreBeGreat picture IAreBeGreat · May 11, 2018 · Viewed 8.4k times · Source

I created this bot using C# to help my alliance out in a phone game. We are using discord to communicate. One of the functions of my bot is to set up "Raid Lane" so people can claim the path they are going to take. Our alliance has an image set spread out across our discord, I want to have the relevant image to each raid be posted when the bot sets up the raid lanes for that difficulty. Currently i have :

var embed = new EmbedBuilder();
            embed.WithTitle("Ultimus Raid - Level 40");

embed.WithImageUrl("https://cdn.discordapp.com/attachments/430797829078908928/441255069518921728/Lvl40raid.png");

await ReplyAsync("", false, embed);

This works kinda. I can see the pictures, but sometimes after i leave and reopen discord all i see is the Title. On the back end where my program is running there is a websocket error. I have tried to get around this by using a local image instead of from a url, just in case that is the problem. I have had no luck getting my bot to post a local image. i have tried

embed.WithImageUrl("C:/Users/Administrator/Desktop/DiscordBot/Pictures/Lvl40raid.png");

as well as with \ instead of /. Also tried the embed.ImageUrl = ... command.

Answer

paul picture paul · May 11, 2018

This works for me (using discord.net):

var guild = _client.Guilds.Single(g => g.Name == "guild name");
var channel = guild.TextChannels.Single(ch => ch.Name == "channel name");
await channel.SendFileAsync("C:\\Pictures\\something.png","Caption goes here");