Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoplay feature #254

Closed
Sikksens opened this issue Sep 30, 2021 · 1 comment
Closed

Autoplay feature #254

Sikksens opened this issue Sep 30, 2021 · 1 comment

Comments

@Sikksens
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Looking to add an autoplay feature to the music system, and want to find where this code would be best placed.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Add either an autoplay command or a toggle button on the current playing track.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

n/a

Additional context
Add any other context or screenshots about the feature request here.

Here is the code

async function autoplay(bot, player) {
    if (!player.queue || !player.queue.previous || player.queue.length > 0) return;

    const URL = `https://www.youtube.com/watch?v=${previoustrack.identifier}&list=RD${previoustrack.identifier}`;
    const response = await bot.manager.search(URL, previoustrack.requester);

    if (!response || response.loadType === 'LOAD_FAILED' || response.loadType !== 'PLAYLIST_LOADED') {
        bot.channels.cache.get(player.textChannel)
           .send("Found nothing related to the last song!").catch(() => { })
        player.destroy();
    }

    let newSong = response.tracks[Math.floor(Math.random() * Math.floor(response.tracks.length))];

    player.queue.add(newSong);
    return player.play();

and then this to call the function when a song ends?

bot.manager
.on("queueEnd", async (player) => {
   autoplay(bot, player);
});
@Spiderjockey02
Copy link
Owner

Sorry for the last response lol, but this has now been implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants