TseShanties
DIAdiscord.js - Imagine an app
•Created by TseShanties on 3/20/2024 in #djs-voice
Bot joining voice channel but not playing audio
Hi everyone. I am making a soundboard and while the bot is successfully joining the voice channel the audio file is not playing. Here are my versions
+-- @discordjs/[email protected]
+-- @discordjs/[email protected]
+-- @discordjs/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
-- [email protected]
Here is where I cam creating my client
```javascript
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates
]
});
```
And here is where I am trying to play an audio file.
```javascript
/// file - '/audio/audioFile.mp3'
const play = (file, voiceChannelId, guild) => {
let voiceConnection = joinVoiceChannel({
channelId: voiceChannelId,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
selfDeaf: false
});
const stream = createReadStream(file);
const resource = createAudioResource(stream);
let audioPlayer = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Stop
}
});
audioPlayer.play(resource);
voiceConnection.subscribe(audioPlayer);
audioPlayer.on(AudioPlayerStatus.Idle, () => {
console.log('end');
//voiceConnection.destroy();
});
audioPlayer.on(AudioPlayerStatus.Playing, () => console.log('playing'))
audioPlayer.on('error', err => console.log(err));
};
```
I am not getting any error messages and both the 'playing' and 'end' logs are printed to the console.
This is code I have from a file called
client.js` the structure in which it is related to the audio file is the following:
5 replies