【问题标题】:DiscordAPIError: Cannot send an empty message with Discord embedDiscordAPIError:无法使用 Discord 嵌入发送空消息
【发布时间】:2021-12-28 11:41:43
【问题描述】:

我的代码如下:

const { Client, Intents, MessageEmbed, MessageAttachment } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on("message", function (message) {


    // inside a command, event listener, etc.
    const exampleEmbed = new MessageEmbed()
        .setColor('#0099ff')
        .setTitle('Some title')
        .setURL('https://discord.js.org/')
        .setAuthor('Some name', 'https://i.imgur.com/AfFp7pu.png', 'https://discord.js.org')
        .setDescription('Some description here')
        .setThumbnail('https://i.imgur.com/AfFp7pu.png')
        .addFields(
            { name: 'Regular field title', value: 'Some value here' },
            { name: '\u200B', value: '\u200B' },
            { name: 'Inline field title', value: 'Some value here', inline: true },
            { name: 'Inline field title', value: 'Some value here', inline: true },
        )
        .addField('Inline field title', 'Some value here', true)
        .setImage('https://i.imgur.com/AfFp7pu.png')
        .setTimestamp()
        .setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png');

    message.channel.send({ embeds: [exampleEmbed] });
    return;

但它给出了以下错误:

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\Federico\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\Federico\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/908380877506089000/messages',
  code: 50006,
  httpStatus: 400
}

它不应该出错,它是原始 Discord.js 文档中的代码:https://discordjs.guide/popular-topics/embeds.html,但确实如此。 我正在运行最新版本的 Discord.JS (13.3.1);和 Node.js v16.9.0。

【问题讨论】:

  • message.channel.send 正确吗?
  • 是的,因为如果我这样做 message.channel.send("wownero.org test") 它可以工作。
  • afaik。当您尝试message.channel.send 时,内容必须是字符串,而现在您正在传递一个对象。这导致了错误。
  • @Kid 不,它接受一个字符串或MessageOptions embeds 是一个属性
  • 你是什么 discord.js 版本?如果您使用 12 发送这样的嵌入是不正确的。尝试通过运行 npm install discord.js@latest 来更新 discord.js

标签: javascript discord discord.js


【解决方案1】:

已修复:由于某些原因,npm install discord.js 实际上并未安装第 13 版,而是第 12 版。谢谢@Christoph Blüm!

【讨论】:

    【解决方案2】:

    我不知道您是如何得到“无法发送空消息”的。 但在 discord.js v13 中,它是 messageCreate 而不是 message。 这对我有用(当你输入“test”时它会发送嵌入):

    client.on("messageCreate", message => {
    
    if (message.content === 'test') {
        const exampleEmbed = new Discord.MessageEmbed()
            .setColor('#0099ff')
            .setTitle('Some title')
            .setURL('https://discord.js.org/')
            .setAuthor('Some name', 'https://i.imgur.com/AfFp7pu.png', 'https://discord.js.org')
            .setDescription('Some description here')
            .setThumbnail('https://i.imgur.com/AfFp7pu.png')
            .addFields(
                { name: 'Regular field title', value: 'Some value here' },
                { name: '\u200B', value: '\u200B' },
                { name: 'Inline field title', value: 'Some value here', inline: true },
                { name: 'Inline field title', value: 'Some value here', inline: true },
            )
            .addField('Inline field title', 'Some value here', true)
            .setImage('https://i.imgur.com/AfFp7pu.png')
            .setTimestamp()
            .setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png');
    
        message.channel.send({ embeds: [exampleEmbed] });
       }
    });
    

    【讨论】:

    • 这不能回答所提出的问题
    猜你喜欢
    • 2021-09-15
    • 2021-12-01
    • 2022-01-23
    • 2020-04-07
    • 2021-12-15
    • 2022-01-01
    • 2021-11-02
    • 2019-03-05
    相关资源
    最近更新 更多