How to get the audioResource

I want to get the audioReasource to delete it, and i'm doing like this when it finish
const resource = createAudioResource(playObj.path);
player.play(resource);

player.on(AudioPlayerStatus.Idle, () => {
try {
resource.playStream.destroy()
resource.playStream = null;
connection.destroy()
connection.disconnect();
} catch (e) {
console.log(e)
}
});
const resource = createAudioResource(playObj.path);
player.play(resource);

player.on(AudioPlayerStatus.Idle, () => {
try {
resource.playStream.destroy()
resource.playStream = null;
connection.destroy()
connection.disconnect();
} catch (e) {
console.log(e)
}
});
but how can i get it if for example i want to use stop cmd Also, is it possible to get it from here player.on(AudioPlayerStatus.Idle, () => {})
10 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
! Alk
! AlkOP15mo ago
The code above showing how would i delete it when someone run play command for example, the resources will be there and i can access it. I’m asking about how can i reach it from different places, for example another command for stopping the audio Sorry for late responding
ShompiFlen
ShompiFlen15mo ago
you can attach the audioplayer to a discord.js structure like guild or your client, then get it from there and call pause on it. You need to be careful on how to keep track of the audio players and where do they belong though the way i personally did it was attaching the audio player to the guild
! Alk
! AlkOP15mo ago
I know how to access the audio player and voice connection, I want to know how can i access the audio resources @ShompiFlen @qjuh i want to delete the stream idk how to explain it, but i think resource.playStream.destroy() will remove the stream from the ram or something like this wdym by references, like this? const resource = createAudioResource(playObj.path);
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
! Alk
! AlkOP15mo ago
great, anything that i can do along with connection.destroy() to have better performance? i really don't know about voices, i use:
"@discordjs/opus": "^0.9.0",
"ffmpeg": "^0.0.4",
"ffmpeg-static": "^5.1.0",
"libsodium-wrappers": "^0.7.11",
"@discordjs/opus": "^0.9.0",
"ffmpeg": "^0.0.4",
"ffmpeg-static": "^5.1.0",
"libsodium-wrappers": "^0.7.11",
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
! Alk
! AlkOP15mo ago
mp3 file thx for your help pp904
Want results from more Discord servers?
Add your server