【发布时间】: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 不,它接受一个字符串或
MessageOptionsembeds是一个属性 -
你是什么 discord.js 版本?如果您使用 12 发送这样的嵌入是不正确的。尝试通过运行
npm install discord.js@latest来更新 discord.js
标签: javascript discord discord.js