require('dotenv').config(); const { Client, MessageEmbed, Collection } = require('discord.js'); const fetch = require('node-fetch'); const ytdl = require('ytdl-core'); const ytSearch = require('yt-search'); const client = new Client(); const CMD_PREFIX = "!" client.on('message', (message) => { if (message.author.bot) return; if (message.content.startsWith(CMD_PREFIX)) { const commandReply = parseCMD(message); if (commandReply && (typeof commandReply != "object")) { message.reply(commandReply); } else if(!commandReply){ generateConfusionGif(message); } } else { const replyMessage = parseCasualMessage(message); if (replyMessage) { message.reply(replyMessage); } else { } } }); function parseCasualMessage(message) { const { content } = message; switch (content.trim().toLowerCase()) { case 'hello': case 'hi': return `Hey ${message.author} ๐Ÿ™‹โ€โ™‚๏ธ. How Are You?`; case 'เดนเดฒเต‹': case 'เดนเดฟ': return `เดนเดฒเตเดฒเดพ.... เด‡เดคเดพเดฐเดพ ${message.author}เดฏเต‹... เดธเตเด–เด‚ เดคเดจเตเดจเต†?`; case 'เดŽเดจเตเดคเตŠเด•เตเด•เต† เด‰เดฃเตเดŸเต เดตเดฟเดถเต‡เดทเด‚': case 'enthokke und vishesham': case 'enthokkeyund vishesham': return `เด…เด™เตเด™เดฟเดจเต† เดชเต‹เดฃเต...๐Ÿคทโ€โ™‚๏ธ เดธเตเด–เด™เตเด™เดณเตŠเด•เตเด•เต† เดคเดจเตเดจเต†?`; case 'เดฎเดจเตเดธเตเดธเดจเดฒเตเดฒเต‡ เดชเตเดณเตเดณเต†': case 'manusanalle pulle': return `เด‡เดฑเดšเตเดšเดฟเดฏเตเด‚ เดฌเดฑเต‹เดŸเตเดŸเดฏเตเด‚ เดตเต‡เดฃเดพเดฏเดฟเดฐเดฟเด•เตเด•เตเด‚... ๐Ÿคฃ๐Ÿคฃ๐Ÿคฃ`; case 'เดจเต€ เด†เดฐเดพ': case 'nee araa': return `เดคเดพเตป เด†เดฐเดพเดฃเต†เดจเตเดจเต เดคเดจเดฟเด•เตเด•เต เด…เดฑเดฟเดฏเดพเดจเตเดฎเต‡เดฒเต†เด™เตเด•เดฟเตฝ เดคเดพเตป เดŽเดจเตเดจเต‹เดŸเต เดšเต‹เดฏเตเด•เตเด•เต เดคเดพเตป เด†เดฐเดพเดฃเต†เดจเตเดจเต??? เดคเดจเดฟเด•เตเด•เต เดžเดพเตป เดชเดฑเดžเตเดžเต เดคเดฐเดพเด‚ เดคเดพเตป เด†เดฐเดพเดฃเต†เดจเตเดจเต... ๐Ÿคช๐Ÿคช`; default: return null; } } function generateConfusionGif(message) { message.channel.startTyping(); const embed = new MessageEmbed() .setDescription(`I dont understand what you are saying <@${process.env.KLIAS_TAG}> do you know what this guy is asking?`) .setColor("RANDOM"); const randomIndex = Math.floor(Math.random() * 9); fetch(`https://api.tenor.com/v1/random?key=${process.env.TENOR_TOKEN}&q=I%20dont%20understand&limit=10`) .then(res => res.json()) .then(response => { embed.setImage(response.results[randomIndex].media[0].gif.url); message.channel.stopTyping(); message.channel.send(embed); }); } function parseCMD(message) { const [CMD_NAME, ...args] = message.content .trim() .substring(CMD_PREFIX.length) .split(/\s+/); switch (CMD_NAME) { case 'jokes': randomJokes(message); return {}; case 'play' : playMusik(message, args); return {}; case 'stop' : stopMusik(message); return {}; default: return null; } } function randomJokes(message) { message.channel.startTyping(); fetch(`https://official-joke-api.appspot.com/jokes/random`) .then(res => res.json()) .then(response => { message.channel.stopTyping(); if(response) { message.channel.startTyping(); message.reply(response.setup); setTimeout(() => { message.channel.stopTyping(); message.reply(response.punchline); }, 5000) } console.log(response); }) } async function playMusik(message, args) { const voiceChannel = message.member.voice.channel; if (!voiceChannel) { return message.channel.send("Join a voice channel to Play Music"); } const permission = voiceChannel.permissionsFor(message.client.user); if(!permission.has('CONNECT') || !permission.has('SPEAK')) { return message.channel.send("You don't have the permission to play music. ๐Ÿ˜ฅ"); } if(!args.length) { return message.channel.send("Please pass something to play as second argument"); } const connection = await voiceChannel.join(); const video = await searchVideo(args.join(' ')); if(video) { const youtubeStream = ytdl(video.url, {filter: 'audioonly'}); connection.play(youtubeStream, {seek: 0, volume: 1}) .on('finish', () => { voiceChannel.leave(); }); await message.reply(`Now Playing ${video.title}...`); } else { message.channel.send("No music found to play for you mate. Try again! ๐Ÿ‘"); } } async function stopMusik(message) { const voiceChannel = message.member.voice.channel; if (!voiceChannel) { return message.channel.send("Join a voice channel to Execute this command"); } await voiceChannel.leave(); await message.channel.send("Stoping Music... Baye Baye.... ๐Ÿ˜…"); } async function searchVideo(query) { const searchResult = await ytSearch(query); return (searchResult.videos.length > 1) ? searchResult.videos[0] : null; } client.login(process.env.LUL_BOT_TKN) .then(() => { console.log("BOT Logged in"); }) .catch((error) => { console.error("BOT Login Failed ", error); });