Untitled

🧩 Syntax:
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");
const ytdl = require("@neoxr/ytdl-core");
const yts = require("yt-search");

module.exports = {
  config: {
    name: "lyrics",
    version: "1.0",
    author: "Aryan Chauhan",
    countDown: 0,
    role: 0,
    shortDescription: {
      en: "Get lyrics for a song",
    },
    longDescription: {
      en: "This command allows you to get the lyrics for a song. Usage: !lyrics <song name>",
    },
    category: "music",
    guide: {
      en: "{prefix}lyrics <song name>",
    },
  },

  onStart: async function ({ api, event, args }) {
    const songName = args.join(" ");
    if (!songName) {
      // Add reaction here
      api.setMessageReaction("ā›”", event.messageID);
      api.sendMessage(
        "ā›” š—œš—”š—©š—”š—Ÿš—œš—— š—§š—œš—§š—Ÿš—˜\n\nā Please provide a song name!",
        event.threadID,
        event.messageID
      );
      return;
    }

    try {
      // Add reaction here
      api.setMessageReaction("šŸ”", event.messageID);

      // Fetch lyrics
      const lyricsResponse = await axios.get(
        `https://lyrics-api.replit.app/aryan?songName=${encodeURIComponent(songName)}`
      );
      const { lyrics, title, artist, image } = lyricsResponse.data;

      // Fetch song
      const searchResults = await yts(songName);
      if (!searchResults.videos.length) {
        api.sendMessage("āŒ š—¦š—¢š—”š—š š—”š—¢š—§ š—™š—¢š—Øš—”š——\n\nā Sorry, song not found!", event.threadID, event.messageID);
        return;
      }

      const video = searchResults.videos[0];
      const videoUrl = video.url;
      const stream = ytdl(videoUrl, { filter: "audioonly" });
      const fileName = `music.mp3`;
      const filePath = path.join(__dirname, "cache", fileName);

      stream.pipe(fs.createWriteStream(filePath));

      stream.on("response", () => {
        console.info("[DOWNLOADER]", "Starting download now!");
      });

      stream.on("info", (info) => {
        console.info("[DOWNLOADER]", `Downloading ${info.videoDetails.title} by ${info.videoDetails.author.name}`);
      });

      stream.on("end", async () => {
        const audioStream = fs.createReadStream(filePath);
        let message = `šŸ“Œ š—›š—˜š—„š—˜ š—œš—¦ š—Ÿš—¬š—„š—œš—–š—¦\n\nšŸŽ§ š—§š—œš—§š—Ÿš—˜\nāžŖ ${title}\nšŸ‘‘ š—”š—„š—§š—œš—¦š—§ \nāžŖ ${artist} \n\nšŸŽ¶ š—Ÿš—¬š—„š—œš—–š—¦\nāžŖ ${lyrics}`;
        let attachment = await global.utils.getStreamFromURL(image);
        api.setMessageReaction("āœ…", id, () => {}, true);
        api.sendMessage({ body: message, attachment }, event.threadID, (err, info) => {
          let id = info.messageID;
          api.sendMessage({ attachment: audioStream }, event.threadID, () => {
          });
        });
      });
    } catch (error) {
      console.error(error);
      api.sendMessage("Sorry, there was an error getting the lyrics and song!", event.threadID, event.messageID);
    }
  },
};