Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const bot = new Discord.Client();
- const token = 'NTgxMjYzMzU4NTMxOTkzNjE3.XOc53A.AjJ6FyT6_mJwB3MAvijd-xId1Zo';
- const ytdl = require ("ytdl-core")
- const servers ={};
- const PREFIX = '?';
- bot.on('ready',() =>{
- console.log('This bot is online!')
- });
- bot.on('message', message=>{
- let args = message.content.substring(PREFIX.length).split(" ");
- switch(args[0]){
- case 'ping':
- message.reply('pong!');
- break;
- case 'info':
- message.reply('This bot was created by ItszKev to use it on your server click https://discordapp.com/oauth2/authorize?client_id=581263358531993617&scope=bot&permissions=0');
- break;
- case 'clear':
- if(!args[1]) return message.reply('how much should I clear?')
- message.channel.bulkDelete(args[1]);
- break;
- }
- if(message.content.startsWith('?play')) {
- if (!message.member.voiceChannel) return message.channel.send(`Please connect to a voice channel ${message.author}`);
- //checks if the bot is already connected to a voice channel
- if (message.guild.me.voiceChannel) return message.channel.send("Sorry, the bot is already connected to a voice channel");
- //checks if the person put a url
- if (!args[0]) return message.channel.send(" Uh oh, something turned into a oof try again!");
- //validate info
- let validate = await ytdl.validateURL(args[0]);
- //checks validation
- if (!validate) return message.channel.send("Uhhhh wa happend? Try again please");
- //fetches video information
- let info = await ytdl.getInfo(args[0]);
- //stores authors guild channels
- let connection = await message.member.voiceChannel.join();
- //plays the song with url
- let dispatcher = await connection.playStream(ytdl(args[0], { filter: `audioonly`}));
- //song now playing
- message.channel.send(`Now playing: ${info.title}`);
- }
- });
- bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement