Bot Joins Voice Channel but Doesn't Play Audio File (ogg)

I managed to get the bot to join the vc but it just sits there. Here's the code:
const resource = createAudioResource('./sounds', theNumber + '.ogg');
currentPlayer = (currentPlayer+1) % NUM_PlAYERS;
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
const sub = connection.subscribe(players[currentPlayer]);
connection.on(VoiceConnectionStatus.Ready, () => {
players[currentPlayer].play(resource);
});
const resource = createAudioResource('./sounds', theNumber + '.ogg');
currentPlayer = (currentPlayer+1) % NUM_PlAYERS;
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
const sub = connection.subscribe(players[currentPlayer]);
connection.on(VoiceConnectionStatus.Ready, () => {
players[currentPlayer].play(resource);
});
(In this case theNumber is 1, but it will vary based on user input. The ogg sound files are in ./sound/ directory) I have several audio players because I hope to play multiple audio streams at once, not sure if it'll actually work though Here's my package.json:
{
"dependencies": {
"@discordjs/voice": "^0.16.0",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"ffmpeg-static": "^5.2.0",
"libsodium-wrappers": "^0.7.13"
}
}
{
"dependencies": {
"@discordjs/voice": "^0.16.0",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"ffmpeg-static": "^5.2.0",
"libsodium-wrappers": "^0.7.13"
}
}
8 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
the_lego_bros
the_lego_brosOP15mo ago
Discord.js version: [email protected] Node -v: v18.16.1
ShompiFlen
ShompiFlen15mo ago
show your client intents and your folder structure please also i think you are missing one of these dependencies @discordjs/opus or opusscript pretty sure you need at least one of those @discordjs/opus is recommended
the_lego_bros
the_lego_brosOP15mo ago
Sure
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates
],
partials: ["CHANNEL"]
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates
],
partials: ["CHANNEL"]
});
I installed @discordjs/opus and the issue persists
the_lego_bros
the_lego_brosOP15mo ago
No description
the_lego_bros
the_lego_brosOP15mo ago
I'm playing the audio file from an event in the events folder and the sound is from the sounds folder
ShompiFlen
ShompiFlen15mo ago
okay so here why is there a comma separating the path const resource = createAudioResource('./sounds', theNumber + '.ogg'); the first argument should be the entire path to the file that comma is separating it
the_lego_bros
the_lego_brosOP15mo ago
Oh, that's because I had a path.join statement which I removed That was the issue I also had to add a / to replace the path.join
Want results from more Discord servers?
Add your server