Error: Request failed with status code 404

Viewed 26

I am trying to get the lyrics of a song. I use sra (some random api) for this. But it gives me the error in the title of this question. I tried looking at other posts etc but nothing that I tried worked.

My code:

// Get the queue for the server
        var queue = client.player.getQueue(interaction.guildId) //ignore

        if(!queue){
          queue = await client.player.createQueue(interaction.guild);
        } //ignore this too
            

        
        if(queue.playing){
          const currentSong = queue.nowPlaying()
          return;
        }

        let title = interaction.options.getString('song'); // the title of the song

        await interaction.deferReply();

        if(!title){ // u can ignore this if statement
            if(!queue.playing()){
                return await interaction.followUp(
                    'Please provide a valid song and try again!'
                )
            }
            title = queue.nowPlaying();
        }
        
        function substring(length, value){
          const replaced = value.replace('/\n/g', '--');
          const regex = `.{1,${length}}`;
          const lines = replaced
            .match(new RegExp(regex, "g"))
            .map(line => line.replace(/--/g, '\n'));

            return lines;
        }

        const songTitle = title; // the title of the song

        const url = await new URL('https://some-random-api.ml/lyrics'); // the api
        url.searchParams.append('title', songTitle);
        console.log("url: ", url);

        try{
            const { data } = await axios.get(url.href); // the data (data.lyrics = the actual lyrics)

            const embeds = substring(4096, data.lyrics).map((value, index) => {
              const isFirst = index === 0; // add title and thumbnail to first embed only

              return new MessageEmbed({
                 title: isFirst ? `${data.title} - ${data.author}`: null,
                 thumbnail: isFirst ? { url: data.thumbnail.genius }: null,
                 description: value,
              })
            });

            return interaction.followUp({embeds}); // sends the lyrics to the user
        } catch(err){
            console.log(err)
            interaction.followUp({content: 'Sorry but I am not able to find lyrics for that song title',
          })
        }

I think the fault has to do with axios since printing out the url variable since it doesn't give any errors and returns this:

url:  URL {
24.09 20:32:19 [Bot] href: 'https://some-random-api.ml/lyrics?title=despacito',
24.09 20:32:19 [Bot] origin: 'https://some-random-api.ml',
24.09 20:32:19 [Bot] protocol: 'https:',
24.09 20:32:19 [Bot] username: '',
24.09 20:32:19 [Bot] password: '',
24.09 20:32:19 [Bot] host: 'some-random-api.ml',
24.09 20:32:19 [Bot] hostname: 'some-random-api.ml',
24.09 20:32:19 [Bot] port: '',
24.09 20:32:19 [Bot] pathname: '/lyrics',
24.09 20:32:19 [Bot] search: '?title=despacito',
24.09 20:32:19 [Bot] searchParams: URLSearchParams { 'title' => 'despacito' },
24.09 20:32:19 [Bot] hash: ''
24.09 20:32:19 [Bot] }
0 Answers
Related