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

Discord.js机器人Embed无法显示本地图片与自定义颜色问题求助

问题排查与解决方案

1. 本地图片显示异常修复

  • 错误原因:
    • Embed的缩略图属性名拼写错误,你写了首字母大写的Thumbnail,discord.js要求全小写的thumbnail
    • 没有将本地图片作为消息附件同步发送,仅写attachment://地址无法识别
  • 修复方法:先引入MessageAttachment加载同目录下的图片,发送消息时把附件一起传给files参数

2. Embed文字颜色修改说明

  • Discord Embed原生不支持单独修改标题、描述、字段名的文字颜色,仅支持修改Embed左侧侧边条的颜色,也就是你代码里的color属性,你可以替换这个参数的数值来修改侧边条颜色,比如0xFF0000对应红色、0x00FF00对应绿色
  • 如果确实要给部分文字加颜色,可以用Discord支持的ANSI转义码套在代码块里实现

修正后完整代码

const { token, prefix } = require('../config.json');
const Discord = require('discord.js');
const { MessageAttachment } = Discord;
const client = new Discord.Client();

// 监听Bot就绪
client.once('ready', () => onClientReady());

function onClientReady() {
    // 监听频道消息
    client.on('message', (message) => onMessageReceived(message));
}

// 处理接收的消息
function onMessageReceived(message) {    
    if(message.author.bot) return;
    if (message.content.toLowerCase().includes('#1')) {
        // 加载本地图片
        const shipImg = new MessageAttachment('./000793.jpg');
        message.channel.send({ 
            files: [shipImg],
            embed: {
                // 这里可以修改侧边条颜色
                color: 0x3498db,
                title: "SpaceShips #1 New_York",
                url: "http://google.com",
                description: "RANK: 74 / SCORE: 121",
                thumbnail: {
                    url: "attachment://000793.jpg"
                },
                fields: [
                    {
                        name: "__**POWER**__",
                        value: "A-G 0: **39**",
                        "inline": true
                    },
                    {
                        name: "__**POWER**__",
                        value: "E-W: **76**",
                        "inline": true
                    },
                    {
                        name: "__**AUTONOMY**__",
                        value: "EY-W Nrg: **74**",
                        "inline": true
                    },
                    {
                        name: "__**AUTONOMY**__",
                        value: "B-P 0 Nrg: **73**",
                        "inline": true
                    },
                    {
                        name: "__**DISPLACEMENT**__",
                        value: "L-A: **79**",
                        "inline": true
                    },
                    {
                        name: "__**DISPLACEMENT**__",
                        value: "3D-V: **67**",
                        "inline": true
                    },
                    {
                        name: "__**SPECIALS**__",
                        value: "EM-W: **34**",
                        "inline": true
                    },
                    {
                        name: "__**SPECIALS**__",
                        value: "3D-W: **42**",
                        "inline": true
                    }
                ]
            }
        });
    }
}

client.login(token);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 05:45:02