Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client } = require('discord.js');
- // const { TOKEN, PREFIX } = require('./config');
- const ytdl = require('ytdl-core');
- const PREFIX = '()'
- const TOKEN = '.DZ36dA.RiCZ0-xX0l-c8F3iK8FmEhkQRl0'
- const client = new Client({ disabledEveryone: true });
- client.on('warn', console.warn);
- client.on('error', console.error);
- client.on('ready', () => console.log('Hey, Just notifiying i have Started myself up, and i\'ll be ready any moment!'));
- client.on('disconnect', () => console.log('i just disconnected!, making sure you know! i\'ll be reconnecting soon!'));
- client.on('reconnecting', () => console.log('i am reconnecting now!'));
- client.on('message', async msg => {
- if (msg.author.bot) return undefined;
- if (!msg.content.startsWith(PREFIX)) return undefined;
- const args = msg.content.split(' ');
- if (msg.content.startsWith(`${PREFIX}play`)) {
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel) return msg.channel.send('I\'m Sorry but you need to be in a voicechannel to play music!');
- const permissions = voiceChannel.permissionsFor(msg.client.user);
- if (!permissions.has('CONNECT')) {
- return msg.channel.send('i cannot connect to your voice channel!, make sure i have the right permissions!')
- }
- if (!permissions.has('SPEAK')) {
- return msg.channel.send('i cannot speak in this voice channel!, make sure i have the right permissions!')
- }
- try {
- var connection = await voiceChannel.join();
- } catch (error) {
- console.error(`i could not join the voice channel: ${error}`);
- return msg.channel.send(`i could not join the voice channel » Erorr: ${error} «`);
- }
- const dispatcher = connection.playStream(ytdl(args[1]))
- .on('end', () => {
- console.log('song ended!');
- voiceChannel.leave();
- })
- .on('error', error => {
- console.error(error);
- });
- dispatcher.setVolumeLogarithmic(5 / 5);
- }
- });
- client.login(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement