Playing a soundfile

I'm trying to use discord.js voice to play a sound file. Is my thinking in how to get this to work in the right direction here or am I missing important parts here?
...

const resource = createAudioResource(soundfilePath);
this.getAudioPlayer().play(resource);
return;
}

...

getAudioPlayer() {
if (!this._audioPlayer) {
this._audioPlayer = this.createAudioPlayer();
}
return this._audioPlayer;
}

createAudioPlayer() {
return createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
}
...

const resource = createAudioResource(soundfilePath);
this.getAudioPlayer().play(resource);
return;
}

...

getAudioPlayer() {
if (!this._audioPlayer) {
this._audioPlayer = this.createAudioPlayer();
}
return this._audioPlayer;
}

createAudioPlayer() {
return createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
}
2 Replies
d.js toolkit
d.js toolkit16mo 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!
Magikaas
MagikaasOP16mo ago
Discord.js: [email protected] Node: v16.15.1 I'm attempting to play a sound file. The bot joins voice (done through code elsewhere in the bot), but does not start playing sound through the code provided above. Upon logging the resource variable, I am shown an AudioResource variable with a length/playbackDuration of 0, now I'm not sure if this because it is unable to read the file's contents or if it can't read the file itself.
Want results from more Discord servers?
Add your server