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

381
Vistas
Im trying to make a discord music bot, but every time i run the code i get message is not defined error

I'm pretty new at js and I wanted to make a music discord bot. This code was working an hour or so ago without a queue system, so i attempted to add one. The code broke, so I deleted the changes I made and the error still persisted. I still get "ReferenceError: message is not defined" does anyone know what the issue is?

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);
    };
  });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

in the client.on function you are using the message object, but you have named the object msg. I think you need to change that. So it will look like this:

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

What changed is the 2 message objects are renamed to msg

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