Low audio quality issue

I'm using latest version of discord.js and discordjs/@voice but the quality of audio is much lower as compared to listening to same files on my PC. This is my code:
const { createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');

async function playLocalAudioFile(channel, filePath) {
try {
const player = createAudioPlayer();
const resource = createAudioResource(filePath);
player.play(resource);

const connection = channel.guild.voiceStates.cache.get(channel.client.user.id).connection;
connection.subscribe(player);

player.on(AudioPlayerStatus.Idle, () => {
player.stop();
channel.client.emit('songFinished', channel);
});
} catch (error) {
console.error('Error occurred while playing audio:', error);
}
}
const { createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');

async function playLocalAudioFile(channel, filePath) {
try {
const player = createAudioPlayer();
const resource = createAudioResource(filePath);
player.play(resource);

const connection = channel.guild.voiceStates.cache.get(channel.client.user.id).connection;
connection.subscribe(player);

player.on(AudioPlayerStatus.Idle, () => {
player.stop();
channel.client.emit('songFinished', channel);
});
} catch (error) {
console.error('Error occurred while playing audio:', error);
}
}
3 Replies
d.js toolkit
d.js toolkit3mo 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!
Hamzah
Hamzah3mo ago
discord.js: 14.12.1 @discordjs/opus: ^0.9.0, @discordjs/voice: "^0.16.1,
ThePedroo
ThePedroo3mo ago
With a lossy codec and a (potentional) lossy connection with Discord, it will not sound better or the same as playing directly