DiscordAPIError: Cannot send empty message
DiscordAPIError: Cannot send empty message
我正在尝试为我的 fivem 服务器制作一个 discord 机器人。但是当我尝试发送嵌入的消息时出现错误。 完整错误:
DiscordAPIError:无法发送空消息
在 RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
在 processTicksAndRejections(节点:internal/process/task_queues:96:5)
在异步 RequestHandler.push (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
方法:'post',
路径:'/channels/941736918104821820/messages',
代码:50006,
http状态:400
}
新的完整错误:
DiscordAPIError:无效的表单主体
embed.description:此字段为必填项
embeds[0].description:此字段是必需的
在 RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
在 processTicksAndRejections(节点:internal/process/task_queues:96:5)
在异步 RequestHandler.push (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
方法:'post',
路径:'/channels/941736918104821820/messages',
代码:50035,
http状态:400
}
index.js代码在这里:
const {MessageEmbed} = require('discord.js')
const fs = require('fs')
const fivereborn = require('fivereborn-query');
const bot = new Client({
disableEveryone: true
})
const config = require('./config.json')
const prefix = config.prefix
const token = config.token
bot.commands = new Collection();
bot.aliases = new Collection();
bot.categories = fs.readdirSync("./commands/");
["command"].forEach(handler => {
require(`./handlers/${handler}`)(bot);
});
bot.on('ready', () => {
console.log(`${bot.user.username} ✅`)
})
bot.on('message', async message =>{
if(message.author.bot) return;
if(!message.content.startsWith(prefix)) return;
if(!message.guild) return;
if(!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length == 0 ) return;
let command = bot.commands.get(cmd)
if(!command) command = bot.commands.get(bot.aliases.get(cmd));
if(command) command.run(bot, message, args)
})
const ip = config.serverIp
const port = config.serverPort
const sName = config.serverName
var MoonRPEmbed = new MessageEmbed()
function activity(){ // Defines the function
setTimeout(() => { // Starts a loop
fivereborn.query(ip, port, (err, data) => { // Starts a function that allowes us to retrive data from our fivem server
if (err) { // Checks for errors
return console.log(err); // If a error is true then this will log that error and then stop it from going by
} else { // If a error is not true then
if(bot.user!= null)
bot.user.setActivity(`${data.clients} / ${data.maxclients} i byen ${sName}`, { type: "WATCHING" }); // Serts the Status
}
});
activity(); // Runs the function we defined at line 45
}, 1000); // Waits 1 second
}
activity(); // Runs the function again
function status(){
setTimeout(() => {
fivereborn.query(ip, port, (err, data) => {
if (!err) {
console.log(data)
bot.channels.fetch('941736918104821820').then(ch => {
if (ch.isText())
{
ch.bulkDelete(10);
}
})
.catch(console.error);
if (err) { // Checks for errors
return console.log(err); // If a error is true then this will log that error and then stop it from going by
} else { // If a error is not true then
if(bot.user!= null)
bot.user.setActivity(`${data.clients} / ${data.maxclients} i byen ${sName}`, { type: "WATCHING" }); // Serts the Status
MoonRPEmbed = {
color: 'ff0000',
description: 'MoonRP Status',
author: {
name: 'MoonRP Status',
},
fields: [
{
name: 'Server Åben',
value: "``` ✅ ```",
inline: true,
},
{
name: 'Spillere inde',
value: "```"+data.clients+ " / "+ data.maxclients+"```",
inline: true,
},
{
name: 'Server IP',
value: "```cfx.re/join/ybrgv5```",
inline: false,
}
],
timestamp: Math.floor(new Date().getTime() / 1000),//new Date(),
footer: {
text: 'MoonRP Bot',
icon_url: 'https://cdn.discordapp.com/attachments/703252325686575124/934779887112302652/Moonrp_logo-min.png'
},
};
}
bot.channels.fetch('941736918104821820')
.then(channel => {
console.log(MoonRPEmbed);
channel.send({embed:[MoonRPEmbed]})
.then(console.log)
.catch(console.error);
})
.catch(console.error)
//channel.send({ embeds: [MoonRPEmbed] });
} else {
return console.log(err)
}
});
status();
}, 60000); // Waits 10 mins
}
status()
bot.login(token)
discord.js版本为:12.5.3
问题是content: ''
。
如果你只想发送一个嵌入,你需要这样做:
.then(channel => { console.log(MoonRPEmbed); channel.send({embeds:[MoonRPEmbed]})
根本不要包含 content
选项。
通过包含它,但实际上并未在其中放入任何内容,它会尝试发送一条包含空内容和嵌入的消息,而不是没有内容和嵌入的消息。
我修好了。出现错误是因为嵌入的代码必须在异步函数中。我不知道为什么,但它奏效了。
我正在尝试为我的 fivem 服务器制作一个 discord 机器人。但是当我尝试发送嵌入的消息时出现错误。 完整错误: DiscordAPIError:无法发送空消息 在 RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:154:13) 在 processTicksAndRejections(节点:internal/process/task_queues:96:5) 在异步 RequestHandler.push (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:39:14) { 方法:'post', 路径:'/channels/941736918104821820/messages', 代码:50006, http状态:400 }
新的完整错误: DiscordAPIError:无效的表单主体 embed.description:此字段为必填项 embeds[0].description:此字段是必需的 在 RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:154:13) 在 processTicksAndRejections(节点:internal/process/task_queues:96:5) 在异步 RequestHandler.push (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:39:14) { 方法:'post', 路径:'/channels/941736918104821820/messages', 代码:50035, http状态:400 }
index.js代码在这里:
const {MessageEmbed} = require('discord.js')
const fs = require('fs')
const fivereborn = require('fivereborn-query');
const bot = new Client({
disableEveryone: true
})
const config = require('./config.json')
const prefix = config.prefix
const token = config.token
bot.commands = new Collection();
bot.aliases = new Collection();
bot.categories = fs.readdirSync("./commands/");
["command"].forEach(handler => {
require(`./handlers/${handler}`)(bot);
});
bot.on('ready', () => {
console.log(`${bot.user.username} ✅`)
})
bot.on('message', async message =>{
if(message.author.bot) return;
if(!message.content.startsWith(prefix)) return;
if(!message.guild) return;
if(!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length == 0 ) return;
let command = bot.commands.get(cmd)
if(!command) command = bot.commands.get(bot.aliases.get(cmd));
if(command) command.run(bot, message, args)
})
const ip = config.serverIp
const port = config.serverPort
const sName = config.serverName
var MoonRPEmbed = new MessageEmbed()
function activity(){ // Defines the function
setTimeout(() => { // Starts a loop
fivereborn.query(ip, port, (err, data) => { // Starts a function that allowes us to retrive data from our fivem server
if (err) { // Checks for errors
return console.log(err); // If a error is true then this will log that error and then stop it from going by
} else { // If a error is not true then
if(bot.user!= null)
bot.user.setActivity(`${data.clients} / ${data.maxclients} i byen ${sName}`, { type: "WATCHING" }); // Serts the Status
}
});
activity(); // Runs the function we defined at line 45
}, 1000); // Waits 1 second
}
activity(); // Runs the function again
function status(){
setTimeout(() => {
fivereborn.query(ip, port, (err, data) => {
if (!err) {
console.log(data)
bot.channels.fetch('941736918104821820').then(ch => {
if (ch.isText())
{
ch.bulkDelete(10);
}
})
.catch(console.error);
if (err) { // Checks for errors
return console.log(err); // If a error is true then this will log that error and then stop it from going by
} else { // If a error is not true then
if(bot.user!= null)
bot.user.setActivity(`${data.clients} / ${data.maxclients} i byen ${sName}`, { type: "WATCHING" }); // Serts the Status
MoonRPEmbed = {
color: 'ff0000',
description: 'MoonRP Status',
author: {
name: 'MoonRP Status',
},
fields: [
{
name: 'Server Åben',
value: "``` ✅ ```",
inline: true,
},
{
name: 'Spillere inde',
value: "```"+data.clients+ " / "+ data.maxclients+"```",
inline: true,
},
{
name: 'Server IP',
value: "```cfx.re/join/ybrgv5```",
inline: false,
}
],
timestamp: Math.floor(new Date().getTime() / 1000),//new Date(),
footer: {
text: 'MoonRP Bot',
icon_url: 'https://cdn.discordapp.com/attachments/703252325686575124/934779887112302652/Moonrp_logo-min.png'
},
};
}
bot.channels.fetch('941736918104821820')
.then(channel => {
console.log(MoonRPEmbed);
channel.send({embed:[MoonRPEmbed]})
.then(console.log)
.catch(console.error);
})
.catch(console.error)
//channel.send({ embeds: [MoonRPEmbed] });
} else {
return console.log(err)
}
});
status();
}, 60000); // Waits 10 mins
}
status()
bot.login(token)
discord.js版本为:12.5.3
问题是content: ''
。
如果你只想发送一个嵌入,你需要这样做:
.then(channel => { console.log(MoonRPEmbed); channel.send({embeds:[MoonRPEmbed]})
根本不要包含 content
选项。
通过包含它,但实际上并未在其中放入任何内容,它会尝试发送一条包含空内容和嵌入的消息,而不是没有内容和嵌入的消息。
我修好了。出现错误是因为嵌入的代码必须在异步函数中。我不知道为什么,但它奏效了。