Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

378
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda