Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const ffmpeg = require('ffmpeg');
- const yt = require('ytdl-core');
- const spotify = require('spotify-web');
- const weather = require('weather');
- const client = new Discord.Client();
- const token = 'YOUR TOKEN';
- var username = 'VoodButt';
- var password = 'rchtoeisnes';
- var _YouTubeQ = [];
- client.on('ready',()=>{
- console.log('I am ready!');
- });
- // ON MESSAGE
- client.on('message',msg => {
- let prefix="#";
- logMsg(msg.content);
- //Prefix Check
- if(!msg.content.startsWith(prefix))return;
- if(msg.author.bot)return;
- //Command Handling
- if(msg.content.startsWith(prefix + 'ping'))
- {
- msg.channel.sendMessage('pong!');
- }
- else if(msg.content.startsWith(prefix + "#foo"))
- {
- msg.channel.sendMessage("bar!");
- }
- else if(msg.content === "#init")
- {
- const voiceChannel = msg.member.voiceChannel;
- const streamOptions = { seek : 0 , volume : 1};
- var directorypath = 'path';
- var filename = 'TestSong.mp3';
- if(!voiceChannel)
- {
- msg.channel.sendMessage("Not in a voiceChannel");
- }
- else
- {
- voiceChannel.join();
- }
- }
- else if(msg.content.startsWith("##play"))
- {
- //const init
- const voiceChannel = msg.member.voiceChannel;
- const streamOptions = { seek: 0,volume: 1};
- //checks
- if(!voiceChannel)
- {
- msg.channel.sendMessage("Not in a voiceChannel");
- log("Failed to play because the user is not in a voice channel")
- }
- else
- {
- QRepeat(msg);
- /*
- if(_YouTubeQ.length > 0)
- {
- var link = _YouTubeQ.shift();
- const stream = yt(link,{filter :'audioonly'});
- const dispatcher = voiceChannel.connection.playStream(stream,streamOptions);
- dispatcher.on('end', () => {
- });
- }
- else
- {
- msg.channel.sendMessage("The Q is empty!");
- }
- */
- }
- }
- else if(msg.content.startsWith('#add'))
- {
- const yPrefix = "https://www.youtube.com/watch?v=";
- var rest = msg.content.split(" ");
- rest.splice(0,1);
- var link = rest.join(" ");
- _YouTubeQ.push(yPrefix+link);
- msg.channel.sendMessage(link+" added to the Q!");
- }
- else if(msg.content.startsWith('#weather'))
- {
- }
- });
- //ON MEMBER JOIN
- client.on("guildMemberAdd",(server,member)=>
- {
- var name = member.username;
- console.log('New user"${member.user.username}" has joined "${server.name}"');
- server.defaultChannel.sendMessage(username+' has joined the server');
- });
- //ON ERROR
- client.on('error',e=>{console.error(e);});
- client.login(token);
- //Function section
- function logMsg(logMessage)
- {
- var currentdate = new Date();
- var datetime = currentdate.getDate()+"/"+currentdate.getMonth()+"/"+currentdate.getFullYear()+"@"+currentdate.getHours()+":"+currentdate.getMinutes()+":"+currentdate.getSeconds();
- console.log(datetime+" "+logMessage);
- }
- function reconnect()
- {
- }
- function QRepeat(msg)
- {
- logMsg("Repeat of the _YouTubeQ");
- const voiceChannel = msg.member.voiceChannel;
- const streamOptions = {seek: 0,volume: 1};
- if(voiceChannel)
- {
- if(_YouTubeQ.length > 0)
- {
- var link = _YouTubeQ.shift();
- const stream = yt(link, { filter : 'audioonly' } ) ;
- const dispatcher = voiceChannel.connection.playStream(stream,streamOptions);
- dispatcher.on('end',() =>{
- logMsg("on end event triggered");
- QRepeat(msg);
- });
- }
- else
- {
- msg.channel.sendMessage("The Q is empty!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement