Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Cómo resolver "El contenido del mensaje debe ser una cadena no vacía" en node.js

Aquí está mi código,

 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) } })

Este codigo es para minecraft mineflayer con discord. Y este código me da error.

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

RangeError [MESSAGE_CONTENT_TYPE]: el contenido del mensaje debe ser una cadena no vacía. en Function.verifyString (C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414:49) en MessagePayload.makeContent (C:\Users\ArtemiiYT\node_modules\discord.js\src\ estructuras\MessagePayload.js:113:22) en MessagePayload.resolveData (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:128:26) en TextChannel.send (C:\Users\ ArtemiiYT\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:168:61) en Timeout._onTimeout (C:\Users\ArtemiiYT\Desktop\Всё\AFK bot\AFKBOTDS\bot.js:46:25 ) en listOnTimeout (nodo:interno/temporizadores:557:17) en processTimers (nodo:interno/temporizadores:500:7) { [Símbolo(código)]: 'MESSAGE_CONTENT_TYPE' }

Node.js v17.1.0

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No seguí mi camino para ejecutar el código, pero creo que la matriz chatData está vacía. así que cuando intenta .join("\n") todos los elementos dentro de él, solo obtiene una cadena vacía que discord simplemente rechaza y obtiene un error. por lo que es posible que desee verificar si hay algo en la matriz primero.

si está aquí por el código, simplemente agregue esto en la función de intervalo:

 if(chatData.length < 1) { // maybe inform the user there is no new chat message? return; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!