Hamzah
Hamzah
DIAdiscord.js - Imagine an app
Created by Hamzah on 4/22/2024 in #djs-voice
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);
}
}
4 replies