AurelicButter / MargarineBot

A Javascript Discord Bot using Klasa
Apache License 2.0
73 stars 49 forks source link

Music command Error #52

Closed LunaryUStyle closed 4 years ago

LunaryUStyle commented 4 years ago

Hi ! I'm new to discord.js and all that but i was testing your play command :

const yt = require("ytdl-core");

exports.run = async (client, msg) => {
  const handler = client.queue.get(msg.guild.id);
  if (!handler) { throw `Si tu veux rajouter des musiques, utilise : ${msg.guild.settings.prefix}queue [Youtube URL] :3`; }

  if (!msg.guild.voiceConnection) {
    await client.commands.get("join").run(client, msg);
    if (!msg.guild.voiceConnection) { return; }
    return this.run(client, msg);
  }

  if (handler.playing) { 
    if (msg.member.voiceConnection !== msg.guild.voiceConnection) { throw "Je joue dans un autre salon..."; }

    throw "Je joue déjà dans ton salon :D";
  } else { handler.playing = true; }

  (function play(song) {
    if (song === undefined) {
      return msg.channel.send("Toutes les musiques que tu as demandé ont été jouées. Je m'en vais D:").then(() => {
      handler.playing = false;
      return msg.member.voiceChannel.leave();
    });
  }

  msg.channel.send(`📻 Joue : **${song.title}** | À la demande de : ${song.requester}`).catch(err => client.emit("log", err, "error"));

  return msg.guild.voiceConnection.playStream(yt(song.url, { audioonly: true }), { passes: 2 })
    .on("end", () => { setTimeout(() => {
      handler.songs.shift();
      play(handler.songs[0]);
    }, 100); })

    .on("error", err => msg.channel.send(`error: ${err}`).then(() => {
      handler.songs.shift();
      play(handler.songs[0]);
    }));
  }(handler.songs[0]));

  return null;
};

I've translated some things in French because my bot is in French, i get the following error :

(node:13028) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
    at Object.exports.run (c:\Users\Ce Pc\Desktop\Ananas\Commands\play.js:4:32)
    at module.exports (c:\Users\Ce Pc\Desktop\Ananas\Events\message.js:25:9)
    at Client.emit (events.js:189:13)
    at MessageCreateHandler.handle (c:\Users\Ce Pc\Desktop\Ananas\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (c:\Users\Ce Pc\Desktop\Ananas\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (c:\Users\Ce Pc\Desktop\Ananas\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (c:\Users\Ce Pc\Desktop\Ananas\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:189:13)
    at Receiver.receiverOnMessage (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:189:13)
    at Receiver.dataMessage (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\receiver.js:422:14)
    at Receiver.getData (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\receiver.js:352:17)
    at Receiver.startLoop (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\receiver.js:138:22)
    at Receiver._write (c:\Users\Ce Pc\Desktop\Ananas\node_modules\ws\lib\receiver.js:74:10)
    at doWrite (_stream_writable.js:410:12)

I've asked on github of ytdl-core, they tell me : this issue tracker is mainly for tracking ytdl-core errors. and since this error is not coming from ytdl-core Thanks :D

LunaryUStyle commented 4 years ago

I tried to add just the queueadd command, i'll get the same error...

AurelicButter commented 4 years ago

It looks like client.queue isn't initialising properly. I won't be able to get a fix out quickly as I'm working on a big overhaul which will fix quite a few issues. I'll keep my eye out for this as I continue to work on it.

LunaryUStyle commented 4 years ago

Thanks

AurelicButter commented 4 years ago

This should be fixed in the latest release. I'll be closing this now.