4

I coded a bot with node.js. I used the example by Crawl for his music bot. I did everything similar to him. After I finished my build everything worked. Every other command and the play command. But now after 2 weeks the bot joins the voice channel, light up green but has no sound. I updated ffmpeg, @discordjs/opus, ffmpeg-static and downloaded the completed version from ffmpeg but the bot still has no audio. The queue, volume, nowplaying, skip, shuffle, loop everything works. But after I got the video or playlist with the play command the bot only joins light up green but has no audio. So the bot definitly get the url, get the video, get everything he needs to play. But after joining he doesnt use the informations to play. Also he doesnt leave the voicechannel after the song should end.

function play(guild, song) {

  try {

    const ServerMusicQueue = queue.get(guild.id);

    if (!song) {

      ServerMusicQueue.textchannel.send(` Queue ended and left the Voicechannel!`).then(message => message.delete(6000));

      ServerMusicQueue.voiceChannel.leave()

      queue.delete(guild.id)
      return;
    }

    const dispatcher = ServerMusicQueue.connection.playStream(ytdl(song.url, { filter: 'audioonly', quality: 'highestaudio', highWaterMark: 1 << 25 }))
      .on('end', () => {

        var loopset = JSON.parse(fs.readFileSync("./rqs/loopset.json", "utf8"))

        if (!loopset[message.guild.id]) {
          loopset[message.guild.id] = {
            loopset: config.loopset
          }
        }

        var loop2 = loopset[message.guild.id].loopset;

        if (loop2 === "true") {
          play(guild, ServerMusicQueue.songs[0])
          return;
        }

        ServerMusicQueue.songs.shift()

        play(guild, ServerMusicQueue.songs[0])

      })
      .on('error', error => {
        console.error(error)
      });

    dispatcher.setVolumeLogarithmic(ServerMusicQueue.volume / 5);

    ServerMusicQueue.textchannel.send(` Start playing: **${song.title}**`).then(message => message.delete(8000));

  } catch (error2) {

    console.log(error2)

  }

}
async function handleVideo(video, message, voiceChannel, playlist = false) {

                    const ServerMusicQueue = queue.get(message.guild.id)

                    const song = {
                        id: video.id,
                        title: Util.escapeMarkdown(video.title),
                        url: `https://www.youtube.com/watch?v=${video.id}`,
                        duration: video.duration,
                        requested: message.author.username
                    };

                    if(!ServerMusicQueue) {
                        const queueConstruct = {
                            textchannel: message.channel,
                            voiceChannel: voiceChannel,
                            connection: null,
                            songs: [],
                            volume: 5,
                            playing: true,
                        };

                        queue.set(message.guild.id, queueConstruct);

                        queueConstruct.songs.push(song)

                        try {

                        var connection = await voiceChannel.join()

                        queueConstruct.connection = connection;

                        play(message.guild, queueConstruct.songs[0])

                        var loopset = JSON.parse(fs.readFileSync("./rqs/loopset.json", "utf8"))

                        if(!loopset[message.guild.id]){
                                loopset[message.guild.id] = {
                                    loopset: config.loopset
                            }
                        }

                        var loop2 = loopset[message.guild.id].loopset;

                            if(loop2 === "true") {

                            loopset[message.guild.id] = {
                                loopset: "false"
                            }

                            fs.writeFile("./rqs/loopset.json", JSON.stringify(loopset), (err) => {
                                if (err) console.log(err)
                            });
                        }

                        } catch (error) {
                            console.error(`Voicechannel join: ${error}`)
                            queue.delete(message.guild.id);
                            message.channel.send("Error with joining the Voicechannel!").then(message => message.delete(5000));
                            message.delete(4000).catch(console.error);
                            return;
                        }

                    } else {

                        ServerMusicQueue.songs.push(song);
                        if(playlist) return undefined;
                        else return message.channel.send(` **${song.title}** has been added to the queue!`).then(message => message.delete(5000));

                    }

                    return;

                    }

package.json

"dependencies": {
    "@discordjs/opus": "^0.3.2",
    "bufferutil": "^4.0.1",
    "colors": "^1.4.0",
    "discord.js": "^11.6.4",
    "discord.js-commando": "^0.10.0",
    "discord.js-musicbot-addon": "^13.9.1",
    "discordjs-prompter": "^1.3.1",
    "ffmpeg-static": "^4.2.2",
    "file-system": "^2.2.2",
    "html-entities": "^1.3.1",
    "m3u8stream": "^0.7.0",
    "miniget": "^1.7.0",
    "ms": "^2.1.2",
    "node-opus": "^0.3.3",
    "npm": "^6.14.5",
    "simple-youtube-api": "^5.2.1",
    "sqlite": "^3.0.3",
    "sqlite3": "^4.1.0",
    "superagent": "^5.2.2",
    "yt-search": "^1.1.2",
    "ytdl-core": "^2.1.3"
  }
FeX
  • 41
  • 3

1 Answers1

1

Try getting ytdl-core, it may fix the issues.

npm i ytdl-core

If that does not fix the issue, try getting Discord-YTDL-Core (make sure you have ytdl-core kept installed)

npm i discord-ytdl-core
Bombo43453
  • 81
  • 3