Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
589 stars 192 forks source link

Discord bot is not streaming given URL/search #1917

Closed itzlexiiihgfdtzbfhfsdgr closed 2 months ago

itzlexiiihgfdtzbfhfsdgr commented 2 months ago

I am working on a Discord music bot powered by discord-player v6.6.10 and discord.js v14.15.3.

Current behavior Currently, when the user executes the /play command, the bot properly searches for the given URL, grabs the video, joins the channel, and then returns an interaction that the song has been added to the queue. But after that, it does not start the playback and instead immediately disconnects from the channel.

Steps to reproduce the behavior: (using current "up-to-date" usage for player.play on the documentation)

  1. join voice channel
  2. execute /play url command
  3. see errors (if any)

Expected behavior Bot joins channel and begins streaming the given query.

Screenshots Screenshot 2024-06-16 013909

Please complete the following information:

module.exports = { data: new SlashCommandBuilder() .setName('play') .setDescription('Plays a song from YouTube') .addStringOption(option => option.setName('url') .setDescription('The URL or name of the song') .setRequired(true) ), async execute(interaction) { const player = useMainPlayer(); const channel = interaction.member.voice.channel;

    if (!channel) {
        return interaction.reply({
            content: 'You need to be in a voice channel to play music!',
            ephemeral: true
        });
    }

    const query = interaction.options.getString('url', true);
    await interaction.deferReply();

    try {
        const { track } = await player.play(channel, query, {
            nodeOptions: {
                metadata: interaction
            }
        });

        return interaction.followUp(`**${track.cleanTitle}** enqueued!`);
    } catch (e) {
        console.error('Error:', e);
        return interaction.followUp(`Something went wrong: ${e.message || e}`);
    }
}

};

twlite commented 2 months ago

Since you are using youtube, you need to try each of these lib until you find one that works for you https://github.com/Androz2091/discord-player?tab=readme-ov-file#streaming-library