Soy bastante nuevo en js y quería hacer un bot de discordia musical. Este código funcionaba hace aproximadamente una hora sin un sistema de cola, así que intenté agregar uno. El código se rompió, así que eliminé los cambios que hice y el error aún persistía. Sigo recibiendo "ReferenceError: el mensaje no está definido". ¿Alguien sabe cuál es el problema?
const Discord = require('discord.js'); const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]}); const config = require('./config.json'); client.music = require("discord.js-musicbot-addon"); var queue= new Array(); client.on("message", (msg) => { if (msg.author.bot) return; const client = msg.client; // Get the command from the message. const command = message.substring(musicbot.botPrefix.length).split(/[ \n]/)[0].trim(); // Get the suffix, the String after the command. const suffix = message.substring(musicbot.botPrefix.length + command.length).trim(); let prefix = "<3" if (msg.content.startsWith(prefix) && command == "play") { // pass the Message Object (msg) and the suffix. queue.push(msg) for(var i=0; i <= queue.length; queue.length--){ client.music.bot.playFunction(queue[0], suffix); } queue.splice(0,1); }; });en la función client.on está utilizando el objeto de mensaje, pero ha nombrado el objeto msg . Creo que tienes que cambiar eso. Entonces se verá así:
const Discord = require('discord.js'); const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]}); const config = require('./config.json'); client.music = require("discord.js-musicbot-addon"); var queue= new Array(); client.on("message", (msg) => { if (msg.author.bot) return; const client = msg.client; // Get the command from the message. const command = msg.substring(musicbot.botPrefix.length).split(/[ \n]/)[0].trim(); // Get the suffix, the String after the command. const suffix = msg.substring(musicbot.botPrefix.length + command.length).trim(); let prefix = "<3" if (msg.content.startsWith(prefix) && command == "play") { // pass the Message Object (msg) and the suffix. queue.push(msg) for(var i=0; i <= queue.length; queue.length--){ client.music.bot.playFunction(queue[0], suffix); } queue.splice(0,1); }; }); Lo que cambió es que los 2 objetos de message se renombraron a msg