Discord bot No song found

So basically, I have 2 command (Play and Loop). The play command works well but the loop don’t detect the song. I think they don’t have the same queue system but I can’t found where.

PLAY COMMAND

const ytdl = require(‘ytdl-core’);
const ytSearch = require(‘yt-search’);

module.exports = {
config: {
name: ‘play’,
noalias: ‘No Aliases’,
category: “music”,
description: ‘Play Command!’,
usage: " ",
accessableby: “everyone”
},
run: async (bot, message, args, ops) => {
const voiceChannel = message.member.voice.channel;

   if (!voiceChannel) return message.channel.send('You need to be in a channel to execute this >command!');
   const permissions = voiceChannel.permissionsFor(message.client.user);
   if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct >permissions');
   if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct >permissions');
   if (!args.length) return message.channel.send('You need to send the second argument!');

   const validURL = (str) =>{
       var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
       if(!regex.test(str)){
           return false;
       } else {
           return true;
       }
   }

   if(validURL(args[0])){

       const  connection = await voiceChannel.join();
       const stream  = ytdl(args[0], {filter: 'audioonly'});

       connection.play(stream, {seek: 0, volume: 1})
       .on('finish', () =>{
           voiceChannel.leave();
           message.channel.send('leaving channel');
       });

       await message.reply(`:thumbsup: Now Playing ***Your Link!***`)

       return
   }

   
   const  connection = await voiceChannel.join();

   const videoFinder = async (query) => {
       const videoResult = await ytSearch(query);

       return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;

   }

   const video = await videoFinder(args.join(' '));

   if(video){
       const stream  = ytdl(video.url, {filter: 'audioonly'});
       connection.play(stream, {seek: 0, volume: 1})
       .on('finish', () =>{
           voiceChannel.leave();
       });

       await message.reply(`:thumbsup: Now Playing ***${video.title}***`)
   } else {
       message.channel.send('No video results found');
   }
}
}

LOOP COMMAND

module.exports = {
config: {
name: ‘loop’,
aliases: [“repeat”],
category: “music”,
description: ‘Repeats all songs in the queue’,
usage: " ",
accessableby: “everyone”
},
run: async (bot, message, args, ops) => {
const { channel } = message.member.voice;
if (!channel) return message.channel.send(‘I'm sorry but you need to be in a voice channel to loop music!’);
const serverQueue = ops.queue.get(message.guild.id);
try {
if (!serverQueue) return message.channel.send(‘There is nothing playing.’);
if (message.guild.me.voice.channel !== message.member.voice.channel) {
return message.channel.send(“You Have To Be In The Same Channel With The Bot!”);
}
if (!serverQueue.loop) {
serverQueue.loop = true;
return message.channel.send(‘:repeat: The queue repeat has been enabled.’);
} else {
serverQueue.loop = false;
return message.channel.send(‘:repeat: The queue repeat has been disabled.’);
}
} catch {
serverQueue.connection.dispatcher.end();
await channel.leave();
return message.channel.send(“Something Went Wrong, Please Try Again!”);
}
}
};

I really wish we can find a solution cause I have been working on it for months

Try setting the YouTube Video ID as a variable, then have it play that.
Alternatively you could try to make the data stream that YTDL generates into a variable and have it play that instead. I honestly am not sure if this will help as my bot doesn’t have a queue system since I can’t figure it out lol, but hopefully it will help at least somewhat.

Happy coding!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.