Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bot.on("message", msg => {
- let prefix = "!";
- if (!msg.content.startsWith(prefix)) return;
- const voiceChannel = msg.member.voiceChannel;
- if (msg.content.startsWith(prefix + "summon")) {
- if (!voiceChannel) return msg.channel.send("Connect to a channel first");
- msg.member.voiceChannel.join();
- msg.channel.send("using !summon before !play is not nessecary");
- }
- if (msg.content.startsWith(prefix + "play") || msg.content.startsWith(prefix + "yt")) {
- if (!voiceChannel) return msg.channel.send("Connect to a channel first");
- msg.member.voiceChannel.join().then(connection => {
- var rest = msg.content.split(" ");
- rest.splice(0, 1);
- rest = rest.join(" ");
- youtube.setKey(key);
- youtube.search(rest, 2, function(error, result) {
- if (error) {
- return console.log('bad link');
- // console.log(error);
- } else {
- if (JSON.stringify(result.items[0]) == undefined) {
- return msg.channel.send("bad link");
- } else {
- title = JSON.stringify(result.items[0].snippet.title);
- url = result.items[0].id.videoId;
- song[0] = 'https://www.youtube.com/watch?v=' + url;
- if (url === undefined) {
- return msg.channel.send("bad link");
- } else {
- (function playSong(currentSong) {
- dispatcher = connection.playStream(yt(currentSong, {
- audioonly: true
- }), {
- passes: 1
- });
- let collector = msg.channel.createCollector(m => m);
- collector.on('collect', m => {
- if (m.content.startsWith(prefix + "pause")) {
- if (dispatcher === undefined) {
- return msg.channel.send("nothing to pause");
- } else {
- msg.channel.send("paused!");
- dispatcher.pause();
- }
- }
- if (m.content.startsWith(prefix + "skip")) {
- if (dispatcher !== undefined) {
- collector.stop();
- dispatcher.end();
- } else return msg.channel.send("nothing to skip");
- }
- if (m.content.startsWith(prefix + "resume")) {
- if (dispatcher !== undefined) {
- dispatcher.resume();
- msg.channel.send("resumed!");
- } else return msg.channel.send("nothing to resume");
- }
- });
- dispatcher.on('end', () => {
- console.log("ended");
- collector.stop();
- bot.user.setPresence({
- game: {
- name: 'Type !help For Commands',
- type: 0
- }
- });
- });
- msg.channel.send("playing " + title);
- console.log("Downloading" + " - " + title);
- bot.user.setPresence({
- game: {
- name: title,
- type: 0
- }
- });
- })(song[0]);
- }
- }
- }
- });
- });
- }
- if (msg.content.startsWith(prefix + "add")) {
- if (!voiceChannel) return msg.channel.send("Connect to a channel first");
- var rest = msg.content.split(" ");
- rest.splice(0, 1);
- rest = rest.join(" ");
- youtube.setKey(key);
- youtube.search(rest, 2, function(error, result2) {
- title = JSON.stringify(result2.items[0].snippet.title);
- url = result2.items[0].id.videoId;
- queue = 'https://www.youtube.com/watch?v=' + url;
- if (url === undefined) {
- return msg.channel.send("bad link");
- } else {
- song.push(queue);
- song.shift();
- msg.channel.send("added to queue!");
- console.log("Added" + " - " + title);
- }
- });
- }
- if (msg.content.startsWith(prefix + "clean")) {
- var rest = msg.content.split(" ");
- rest.splice(0, 1);
- rest = rest.join(" ");
- if (isNaN(rest) === false && rest < 100) {
- msg.channel.bulkDelete(rest);
- } else {
- msg.channel.send("Bot can only clean a value of 1 - 100 messages");
- }
- console.log(msg.author.username + " deleted " + rest + " messages");
- }
- if (msg.content.startsWith(prefix + "ip")) {
- msg.author.send('braydenserver.serveftp.com');
- msg.channel.send("IP has been direct messaged");
- console.log(msg.author.username + " requested the ip")
- }
- if (msg.content.startsWith(prefix + "help")) {
- msg.channel.send(" commands: \n \n \
- summon = Summons the bot to a voice channel \n \
- play + URL or yt + URL = joins voice channel and plays the url the user requested \n \
- puase = Puases current song \n \
- Skip = Skips to next song in queue \n \
- resume = Resumes current song in queue \n \
- add + URL = Appends the URL to the end of the queue \n \
- queue = Puts the songs that are currently in queue into the chat \n \
- clear = Deletes every song from queue \n \
- clean + Number = deletes however many messages (specified by number -1 because of bug) \n \
- leave = Bot leaves voice chat \n \
- ping = pong \n \
- ip = direct messages the ip in the form of a dns or url \
- ");
- }
- if (msg.content.startsWith(prefix + "leave")) {
- if (!msg.guild.member(bot.user).voiceChannel) {
- return (msg.channel.send("Bot is not summoned!"))
- } else {
- msg.guild.member(bot.user).voiceChannel.leave();
- }
- }
- if (msg.content.startsWith(prefix + "ping")) {
- msg.channel.send("pong!");
- }
- if (msg.content.startsWith(prefix + "queue")) {
- if (song[1] !== undefined) {
- msg.channel.send(song);
- } else return msg.channel.send("Nothing in queue. !add to add a song to queue");
- }
- if (msg.content.startsWith(prefix + "clear")) {
- if (song !== undefined) {
- song = [];
- msg.channel.send("Queue has been cleared");
- } else return msg.channel.send("The queue is already empty");
- }
- });
- bot.on('ready', () => {
- bot.user.setPresence({
- game: {
- name: 'Type !help For Commands',
- type: 0
- }
- });
- console.log('Bot is online');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement