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

433
Vistas
Discordjs 13 bot not playing local mp3 file

I can't figure out why my bot is not playing music. This is my code.

if (command === 'song') {
    const player = createAudioPlayer();

    joinVoiceChannel({
        channelId: message.member.voice.channel.id,
        guildId: message.guild.id,
        adapterCreator: message.guild.voiceAdapterCreator
    }).subscribe(player);

    message.guild.me.voice.setRequestToSpeak(true);
    const resource = createAudioResource('music/song.mp3');
    player.play(resource);
}

I'm using Discordjs 13, installed all the required modules... the bot joins the voice channel but it doesn't play the song in my local folder. Edit: The console does not return errors, the bot has administrator permissions and it is not muted or deafened.

Edit 2: This is the report I got from the console when I use generateDependenciesReport()

--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.7.4
- prism-media: 1.3.2

Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found

Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: not found

FFmpeg
- version: 4.4.1-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------

And I think that everything's okay but the bot is still not playing music

Edit 3:
I edited my code to this

if (!message.member.voice.channel) {
                return
            } else if (message.member.voice.channel) {

                const connection = joinVoiceChannel({
                    channelId: message.member.voice.channel.id,
                    guildId: message.guild.id,
                    adapterCreator: message.guild.voiceAdapterCreator
                });

                const player = createAudioPlayer();
                const resource = createAudioResource('./music/song.mp3');
                //play the song resource
                player.play(resource);
                connection.subscribe(player);
            }

Still no console errors, the bot joins the voice channel but it doesn't play the .mp3 file. Any ideas ?

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

0

I finally solved my problem.
The thing I was missing was an intent of the client. It was GUILD_VOICE_STATES.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this code:

const { Client, Intents } = require('discord.js');
const {
    joinVoiceChannel,
    createAudioPlayer,
    createAudioResource
} = require('@discordjs/voice');

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_VOICE_STATES // <= Don't miss this :)
    ]
});

client.on('ready', () => {
    console.log(`Logged in as ${client.user.username}`);
})

client.on('messageCreate', async (message) => {
    if (message.content === '!play') {
        if (!message.member.voice?.channel) return message.channel.send('You need to be a voice channel to execute this command')

        const connection = joinVoiceChannel({
            channelId: message.member.voice.channelId,
            guildId: message.guildId,
            adapterCreator: message.guild.voiceAdapterCreator
        })

        const player = createAudioPlayer()
        const resource = createAudioResource('./music/song.mp3')

        connection.subscribe(player)

        player.play(resource)
    }
})

client.login('Token Here')

Here's my package.json file:

{
  "name": "discord_bot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@discordjs/opus": "^0.5.3",
    "@discordjs/voice": "^0.7.5",
    "discord.js": "^13.5.0",
    "libsodium-wrappers": "^0.7.9"
  }
}

Note: I have already installed ffmpeg, so I don't need to use ffmpeg-static

Also check here to find out which dependencies you've successfully installed.

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