How do I detect once the music has finished (djs v13.12.0) [Solved]

I have messed around with the player.on() function with createAudioPlayer and such but I can not find a solid way to loop it? Heres my code:
player.on('stateChange', () => {
if (currentSong === null) {
player.stop()
resource = null
} else {
player.play(resource)
}
}
player.on('stateChange', () => {
if (currentSong === null) {
player.stop()
resource = null
} else {
player.play(resource)
}
}
I have tried unsubscribe, state change, idle and error and every single one just doesn't work Can somebody help me? I do not have any errors at all in the output and I put a console.log in the player and it wouldn't print anything
13 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ShompiFlen
ShompiFlen2y ago
does the bot play audio at all?
The Blade
The BladeOP2y ago
I have code outside of it to play it and it plays that, it doesn't trigger the player.on event though
const player = createAudioPlayer()
Currentplayer = player
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
}).subscribe(player)

if (message.guild.me.voice.channelId === "1075934013946077204") {
message.guild.me.voice.setRequestToSpeak(true);
}

const resource = createAudioResource(currentSongLocation, {
metadata: {
title: 'A test song!',
},
inlineVolume: true,
});
player.play(resource)
resource.volume.setVolume(volume)
voiceChannelResource = resource
message.reply("Playing song, volume is " + resource.volume.volume)
player.on('', () => {
if (currentSong === null) {
player.stop()
resource = null
} else {
player.play(resource)
}
})
const player = createAudioPlayer()
Currentplayer = player
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
}).subscribe(player)

if (message.guild.me.voice.channelId === "1075934013946077204") {
message.guild.me.voice.setRequestToSpeak(true);
}

const resource = createAudioResource(currentSongLocation, {
metadata: {
title: 'A test song!',
},
inlineVolume: true,
});
player.play(resource)
resource.volume.setVolume(volume)
voiceChannelResource = resource
message.reply("Playing song, volume is " + resource.volume.volume)
player.on('', () => {
if (currentSong === null) {
player.stop()
resource = null
} else {
player.play(resource)
}
})
Theres the full code
ShompiFlen
ShompiFlen2y ago
well you are not listening to any event right now player.on(' ') that is not gonna trigger at any time
The Blade
The BladeOP2y ago
Yes, but before I was and that wouldn't work so I just kept it on '' while im searching online trying to find fixes So whenever I can see a thing that might work, I don't have to delete it and can just put it in
ShompiFlen
ShompiFlen2y ago
so you want to check whether or not the player is playing audio?
The Blade
The BladeOP2y ago
searching online right now, can't find anything besides idle which isn't even an option I want the player to loop
ShompiFlen
ShompiFlen2y ago
okay import AudioPlayerStatus from discordjs/voice
The Blade
The BladeOP2y ago
Done
ShompiFlen
ShompiFlen2y ago
then do player.on(AudioPlayerStatus.Idle, () => { and just put player.play(resource) inside
The Blade
The BladeOP2y ago
Ah, thank you. The only things I could actually find were with "Idle" on stack overflow but they were telling me to do AudioPlayer.Idle, not AudioPlayerStatus.Idle Thanks for the help
The Blade
The BladeOP2y ago
I was looking there, but only in AudioPlayer
Want results from more Discord servers?
Add your server