Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

312
Vistas
discord.js bot playing audio but no sound?

I was planning to add some voice features to my discord bot, but for some reason when I run my code, it doesn't make sound while discord does show the green circle around my bot, showing that it's making sound. It also does't log any errors or anything else, does anyone know what's wrong with my code?

Code:

        if (command == "soundtest") {
            mongo().then(async (mongoose) => {
                const { voice } = msg.member

                if (voice.channelID) {
                    const vc = voice.channel
                    // console.log(channel)
                    try {
                        vc.join().then(connection => {
                            connection.play(path.join(__dirname, 'Bastille_Pompeii.mp3'))
                        })
                    } catch(e) {
                        console.log("error")
                        console.log(e)
                    }
                } else {
                    msg.channel.send(`You must join a voice channel to use this command`)
                }
            })
        }

Thanks for reading!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This code should work for you:

const { createReadStream } = require('fs');
const { join } = require('path');
const { createAudioResource, StreamType, createAudioPlayer, joinVoiceChannel } = require('@discordjs/voice');
const player = createAudioPlayer()
joinVoiceChannel({
    channelId: message.member.voice.channel.id,
    guildId: message.guild.id,
    adapterCreator: message.guild.voiceAdapterCreator
}).subscribe(player)
let resource = createAudioResource(join('./folder/', '<song_name>.mp3'));

player.play(resource)

As you said, you tried to play file named Bastille_Pompeii.mp3, so you need to define resource like this: let resource = createAudioResource(join('./musicfiles/', 'Bastille_Pompeii.mp3'));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda