Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

312
Visualizações
Problems playing audio files in Discord

So, It's been two long days traying to figure what the reck is going on... I'm creating a Bot to my Discord Channel that plays an audio.mp3 when a command is written, like !laugh then the bot should enter the voice channel and reproduce laugh.mp3. I've tried in so manny different ways but the bot keeps entering the channel, the green circle quickly appears but no sound is played...

const { join } = require('path');
const { joinVoiceChannel,  createAudioPlayer,  createAudioResource, getVoiceConnection, entersState, StreamType,  AudioPlayerStatus,  VoiceConnectionStatus, AudioResource } = require("@discordjs/voice");

module.exports = {
   name: 'laugh', 
   aliases: ["l"], 

   run: async(client, message, args) => {

   const player = createAudioPlayer()
   const connection = joinVoiceChannel({
   channelId: message.member.voice.channel.id,
   guildId: message.guild.id,
   adapterCreator: message.guild.voiceAdapterCreator
                     }).subscribe(player)
   let resource = createAudioResource(join('./som/', 'laugh.mp3'));
   player.play(resource)
   player.on(AudioPlayerStatus.AutoPaused, () => {
   player.stop();
         
     });
   }
}

I've already tried to caugh error but apparently nothing is wrong, I already have all intents in my index.js.

So, anyone could help me find a solution?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Past the 3rd day I resolved to find other library I could use to solve the problem, turns out I found a solution using FS!

Instead of only try to play the file, I've created a stream and then I just play the stream... In terms of performance that's not the greatest solution ever, but it works!

That's how it goes:

   const {createReadStream } = require('fs')
   const { join } = require('path');
   const { joinVoiceChannel,  createAudioPlayer,  createAudioResource, 
   getVoiceConnection, entersState, StreamType,  AudioPlayerStatus,  
   VoiceConnectionStatus, AudioResource } = require("@discordjs/voice");

   module.exports = {
   name: 'laugh', 
   aliases: ["l"], 

   run: async(client, message, args) => {
   const player = createAudioPlayer();
   const connection = joinVoiceChannel({
   channelId: message.member.voice.channel.id,
   guildId: message.guild.id,
   adapterCreator: message.guild.voiceAdapterCreator,
   selfDeaf: false,
                }).subscribe(player);

   let resource = createAudioResource(createReadStream(join(__dirname, 'som/laugh.mp3')), {
   inlineVolume : true
});
   resource.volume.setVolume(0.9);
   console.log(join(__dirname, 'som/laugh.mp3'));

   player.play(resource)
   player.on(AudioPlayerStatus.AutoPaused, () => {
   player.stop();
         
    });

Something I must alert is about Replit not resolving properly Node.js 17 and other dependencies, so to bring your Bot up 24/7 use Heroku and GitHub. To finish the GUILD_VOICE_STATES Intents are required to be set, I was using 32767 but somehow this wasn't working.

That's it!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda