Bot joining but not playing

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


module.exports = {
  name: 'audio',


  execute: async function(message, client, args, user, member) {
    try{
 
      const voiceChannel = message.member.voice?.channel;
      
      if (!voiceChannel) {          
        return message.reply('Entra a un canal de voz primero.');     
      }

      const connection = joinVoiceChannel({
        channelId: voiceChannel.id,
        guildId: voiceChannel.guild.id,
        adapterCreator: voiceChannel.guild.voiceAdapterCreator,
      });

      const player = createAudioPlayer();
      
      const audio = createAudioResource('./audios/audio1.mp3', {
        metadata: {
          title: 'Audio1',
        },
      });
      
      if(connection) {
        message.reply(`Conectado al canal de voz <#${voiceChannel.id}>`)
        player.play(audio)
        console.log("Playing")
      }
      

      if(connection) {
      setTimeout(() => connection.destroy(), 5_000);
      setTimeout(() => player.stop(), 5_000);
      }

    } catch (error) {
      console.error(error);
      return false;
    }
  }
  
}

The bot join the channel but does not play the audio, there is not errors.
Was this page helpful?