Local Audio Streams

I've been trying for the last 4 hours to try and get local audio files or audio streams to work with djs and im still quite lost. I've tried everything and read the docs, im just not understanding how to do this. All I want for now is to play a local audio file in a voice channel, so that I can move forward I've gotten some weird errors, but I feel like Im going about this all wrong. Help very much needed
5 Replies
d.js toolkit
d.js toolkit14mo 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!
ItsActuallyTJ
ItsActuallyTJOP14mo ago
djs: 14.13.0 node: v18.17.1 djs voice: 0.16.0 not sure if it matters, but im running all this in es6 format
const playAudioInVoiceChannel = async (interaction, filePath) => {

console.log('playing!')

const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});

let src = await createAudioResource(filePath, {
inputType: StreamType.Arbitrary,
});

const player = await createAudioPlayer();
await connection.subscribe(player);
await player.play(src);

console.log('finished!');
};
const playAudioInVoiceChannel = async (interaction, filePath) => {

console.log('playing!')

const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});

let src = await createAudioResource(filePath, {
inputType: StreamType.Arbitrary,
});

const player = await createAudioPlayer();
await connection.subscribe(player);
await player.play(src);

console.log('finished!');
};
Nounejm
Nounejm14mo ago
you dont have to await any of that but make sure the right path gets to the resource
duck
duck14mo ago
on top of confirming the path, you'll also want to check: - that the file is valid - that you have the proper dependencies to play the given file - that your connection enters the ready state (and check if you have the GuildVoiceStates intent if it doesn't) - whether the player goes through its lifecycle as expected
d.js docs
d.js docs14mo ago
To debug your voice connection and player: - Use debug: true when creating your VoiceConnection and AudioPlayer - Add an event listener to the <VoiceConnection> and the <AudioPlayer>:
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
- Add an error listener to the stream you are passing to the resource:
<Stream>.on('error', console.error)
<Stream>.on('error', console.error)
Note: The <> represents classes that need to be adapted to their respective name in your code
guide Getting Started: Introduction - Debugging Dependencies read more
Want results from more Discord servers?
Add your server