【发布时间】:2021-09-02 05:27:58
【问题描述】:
我正在关注有关如何编写不和谐机器人的 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 年还没有看到任何关于这个错误的问题得到解答,所以我想我会在这里拍摄,提前谢谢。
【问题讨论】:
标签: javascript discord.js