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 client = new Client({ disableEveryone: true });
- client.on('warn', console.warn);
- client.on('error', console.error);
- client.on('ready', () => console.log('Yo this ready!!!'));
- client.on('disconnect', () => console.log('I just disconnected, making sure you now, I will reconnect now'));
- 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 on a voice channel 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 proper permissions!');
- }
- if (!permissions.has('SPEEK')) {
- return msg.channel.send('I cannot speek in this channel, make sure I have proper 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 : ${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