0

我试图为我的 Fivem 服务器制作一个不和谐的机器人。但是当我尝试发送消息嵌入时出现错误。完全错误: DiscordAPIError: Cannot send an empty message at RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest\RequestHandler.js:154:13) at processTicksAndRejections (node: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,httpStatus:400 }

新的完整错误: DiscordAPIError: Invalid Form Body embed.description: This field is required embeds[0].description: This field is required at RequestHandler.execute (D:\DiscordBots\MoonRP\node_modules\discord.js\src\rest \RequestHandler.js:154:13) 在 processTicksAndRejections (node: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,httpStatus: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

4

2 回答 2

0

问题是content: ''。如果您只想发送嵌入,则需要这样做:

.then(channel => { console.log(MoonRPEmbed); channel.send({embeds:[MoonRPEmbed]})

根本不包括content选项。通过包含它,但实际上并未在其中放入任何内容,它会尝试发送带有空内容和嵌入的消息,而不是没有内容和嵌入的消息。

于 2022-02-12T11:31:50.013 回答
0

我修好了它。出现错误是因为嵌入的代码必须在异步函数中。我不知道为什么,但它奏效了。

于 2022-02-17T17:11:37.633 回答