You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C#中为Discord机器人发送无附加消息的图片?

解决方法

要发送不带任何文本的图片,你可以用Discord.NET的EmbedBuilder(适合网络图片)或者Attachment(适合本地图片)来实现,修改你的代码如下:

方法一:发送网络图片(用Embed)

public class Command : ModuleBase<SocketCommandContext>
{
    [Command("Image")]
    public async Task ReplyImage()
    {
        // 创建仅包含图片的Embed
        var imageEmbed = new EmbedBuilder()
            .WithImageUrl("你的图片完整URL") // 替换成实际图片链接
            .Build();
        
        // 发送时不传文本内容,只传Embed
        await ReplyAsync(embed: imageEmbed);
    }
}

方法二:发送本地图片(用Attachment)

如果要发送本地存储的图片,用Attachment类:

public class Command : ModuleBase<SocketCommandContext>
{
    [Command("Image")]
    public async Task ReplyImage()
    {
        // 加载本地图片作为附件,using确保资源释放
        using var imageAttachment = new Attachment("本地图片的完整路径");
        
        // 发送时不传文本内容,只传附件
        await ReplyAsync(attachment: imageAttachment);
    }
}

注意点

  • 原来的代码是把图片URL作为文本消息发送,所以只会显示成普通链接,不会渲染成图片。
  • 使用Embed时,要确保图片URL是可公开访问的,Discord才能拉取并显示。

内容的提问来源于stack exchange,提问作者Carrot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 09:25:32