C# Discord Bot - Upload Local Image

一曲冷凌霜 提交于 2019-12-11 15:57:51

问题


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.


回答1:


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");


来源:https://stackoverflow.com/questions/50296205/c-sharp-discord-bot-upload-local-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!