Discord API错误:无法发送空消息



我在YouTube上学习如何编写不和谐音机器人的教程,然后我遇到了臭名昭著的错误"无法发送空消息";试图发送嵌入时。下面是我的代码:

main.js:

const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '!';
const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Picobot is ready for use!');
});

client.on('message', message =>{
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();

if (command === 'ping') {
client.commands.get('ping').execute(message, args);
} else if(command === 'pong') {
client.commands.get('pong').execute(message, args);
} else if(command === 'permissions') {
client.commands.get('permissions').execute(message, args);
}
if (command === 'embed') {
client.commands.get('command').execute(message, args, Discord);
}
});

embed.js:

module.exports = {
name: 'embed',
description: 'Embeds',
execute(message, args, Discord) {
const newEmbed = new Discord.MessageEmbed()
.setColor('#304281')
.setTitle('Rules')
.setURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
.setDescription('This is a test embed')
.addFields(
{name: 'Rule 1', value: 'Placeholder 1'},
{name: 'Rule 2', value: 'Placeholder 2'},
{name: 'Rule 3', value: 'Placeholder 3'},
)
.setImage('https://images.radio-canada.ca/q_auto,w_960/v1/ici-info/16x9/rick-astley-videoclip-never-gonna-give-you-up.png');
message.channel.send({ newEmbed:newEmbed });
}
}

我已经看到许多其他人有这个错误,我发现并尝试到目前为止的唯一解决方案是将message.channel.send({ newEmbed:newEmbed })更改为message.channel.send(newEmbed),但同样的错误仍然弹出。我在2021年还没有看到任何关于这个错误的回答问题,所以我想我会在这里拍摄我的镜头,提前感谢。

从v12过渡到v13,我们遇到了另一个令人厌倦的变化,对一些用户来说没有意义

// message.channel.send(newEmbed) does not work anymore
message.channel.send({
embeds: [newEmbed]
});
// The above is the way to go!

另一个更改:消息事件侦听器:

client.on("message", () => {})

已折旧,改为messageCreate

在v13中发送嵌入的结构如下:

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

Embeds - Discord.JS

最新更新