Я предполагаю, что вы хотите иметь возможность остановить музыку c.
// This stores the voice channel that the bot is connected to for each guild
// mapped by the guild ID so that we can stop the music by leaving the channel.
const voiceChannels = new Map()
if (message.content.startsWith('jukebox play ')) {
const args = messagesansfiltre.split(' ')
console.log(args[2])
const voiceChannel = message.member.voice.channel
if (!voiceChannel) return message.channel.send("I'm sorry but you need to be in a voice channel to play music!")
voiceChannel.join()
.then(connection => {
// Stores the voice channel
voiceChannels.set(message.guild.id, voiceChannel)
// A recursive function that plays the music continuously.
const play = () => {
const dispatcher = connection
.play(ytdl(args[2]))
// When the song is finished, play it again.
.on('finish', play)
// Note that in Discord.js v12 StreamDispatcher has pauseTime, streamTime,
// and totalStreamTime
console.log(dispatcher.time)
}
play()
})
.catch(console.log)
} else if (message.content.startsWith('jukebox stop')) {
// You can send 'jukebox stop' to stop the music.
const voiceChannel = voiceChannels.get(message.guild.id)
if (!voiceChannel) return message.channel.send('No music is playing!')
// Leave the channel.
voiceChannel.leave()
// Remove the channel from voiceChannels.
voiceChannels.delete(message.guild.id)
}
Я не проверял это, поэтому дайте мне знать, если это не работает.