Play command

I was making a play command

        await interaction.deferReply();

            const search = await ytse(given_song);
            const search_res = search.videos[0].url;

            const userchannel = interaction.member.voice;
            if (!userchannel) {return interaction.followUp('You must be in a voice channel to use this command');}

            const audioplayer = createAudioPlayer();

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

            connection.subscribe(audioplayer);

            const ytdlprocess = ytdl(search_res, {filter:'audioonly'});

            ytdlprocess.on("error",(error) => {console.error(error);});

            audioplayer.play(createAudioResource(ytdlprocess));

            await interaction.followUp({content:'Song is playing'});

            audioplayer.on(AudioPlayerStatus.Idle, (oldState, newState) => {//song ended
                connection.destroy();
                return interaction.followUp({content:'Song ended. Leaving channel'});
            });


But sometimes it joins the channel and says 'Song is playing' but does not play anything
Sometimes it does not join the channel only and says 'Song is playing'

It does not log any error also
Was this page helpful?