Reputation: 49
Pretty self-explanatory, really. I'm trying to re-code my Discord audio bot since Discord went and changed their bot API, and despite my best efforts the bot still produces no sound.
Here's the relevant bits of code:
const client = new Discord.Client({
partials: ["MESSAGE", "CHANNEL", "REACTION"],
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES"]
});
let connection;
let player;
async function playMusic() {
player = createAudioPlayer();
connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
}).subscribe(player);
/* some code that sets songFile */
let resource = createAudioResource(createReadStream(songFile));
player.play(resource);
}
Calling this causes the bot to join the voice call, but it plays no sound. It says that the current state is AudioPlayerStatus.Playing
, though, so I don't know what's happening there.
I've verified that the filepath for songFile is correct and the resource is successfully created. All the code is nested in try/catch
blocks, so I know no errors are being raised. I've also included the intents
in case I'm missing one there, but from other questions I've seen on this website GUILD_VOICE_STATES
seems to be the key one.
Any help is appreciated!
Upvotes: 0
Views: 554
Reputation: 124
please visit @discordjs/voice repository, and check Installation
section in README.md. In order to play audio, you have to install several packages, one from each group:
Encryption Libraries (npm install):
sodium-native: ^3.3.0
sodium: ^3.0.2
tweetnacl: ^1.0.3
libsodium-wrappers: ^0.7.9
Opus Libraries (npm install):
@discordjs/opus: ^0.4.0
opusscript: ^0.0.7
FFmpeg:
FFmpeg (installed and added to environment)
ffmpeg-static: ^4.2.7 (npm install)
Hope it helps someone :)
Upvotes: 1