the_lego_bros
the_lego_bros
DIAdiscord.js - Imagine an app
Created by the_lego_bros on 9/19/2023 in #djs-voice
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"
}
}
19 replies