Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
How to solve "Message content must be a non-empty string" in node.js

Here is my code,

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

let sending = false
let chatData = []

let prefix = ".";
var settings = {
    username: "StilShem_tvink",
    host: "mstnw.net",
};

const bot = mineflayer.createBot(settings);

bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn));
bot.on('error', err => console.log(err));

client.on("ready", async =>{
    console.log("Discord bot is online!")
})

bot.on("login", async =>{
    console.log("Minecraft bot is online!")
})

bot.on("message", message => {
    if(sending == true) {
        chatData.push(`${message}`)
    }
})

client.on("messageCreate", async msg => {
    let args = msg.content.split(" ").slice(1)

    if(msg.content.startsWith(".chat")) {
        let toSend = args.join(" ");
        if(!toSend) return msg.reply("No args")

        bot.chat(toSend)
        sending = true
        msg.channel.send(`${msg.author.tag} just sent ${toSend}`)

        setTimeout(() => {
            sending = false
            msg.channel.send(chatData.join("\n"))
            chatData = []
        }, 750)
    }
})

This code is for minecraft mineflayer with discord. And this code give me error.

C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414 if (!allowEmpty && data.length === 0) throw new error(errorMessage); ^

RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string. at Function.verifyString (C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414:49) at MessagePayload.makeContent (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:113:22) at MessagePayload.resolveData (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:128:26) at TextChannel.send (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:168:61) at Timeout._onTimeout (C:\Users\ArtemiiYT\Desktop\Всё\AFK bot\AFKBOTDS\bot.js:46:25) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) { [Symbol(code)]: 'MESSAGE_CONTENT_TYPE' }

Node.js v17.1.0

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I didn't go on my way to run the code, but I think the chatData array is empty. so when you try to .join("\n") all the elements inside it together, you just get an empty string which discord just rejects and you get an error. so you might want to check if there is anything in the array first.

if you are here for the code just add this in the interval function:

if(chatData.length < 1) {
  // maybe inform the user there is no new chat message?
  return;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda