I made a simple music bot that only works with URLs, and what I'm trying to do is to check if in the command argument there is 'stop' (Already done and working), and then stop the music player. The problem is that when player.stop() while music is playing it does not stop. Here is my code:
const ytdl = require('ytdl-core');
module.exports ={
name:'play',
description:'aaaaaaaaaaaam',
async execute(message, args, Discord){
const { joinVoiceChannel, createAudioPlayer, createAudioResource} = require('@discordjs/voice');
const stream = ytdl(args[0], {filter: 'audioonly', quality:'highestaudio', highWaterMark: 1<<25 });
const player = createAudioPlayer();
const resource = createAudioResource(stream);
const {AudioPlayerStatus} = require('@discordjs/voice');
if(ytdl.validateURL(args[0])){
const connection = joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})
connection.subscribe(player);
player.play(resource);
} else if(args[0] === undefined){
const embed = new Discord.MessageEmbed()
.setColor('#0000FF')
.setTitle('Da me chevvoi, te posso canta na canzone')
message.channel.send({ embeds: [embed] });
}
if (args[0] === 'stop'){
player.on(AudioPlayerStatus.Playing, () => {
player.stop();
});
}
const {generateDependencyReport} = require('@discordjs/voice');
console.log(args[0]);
console.log(generateDependencyReport());
}
}