Advertisement
plytalent

discordbot.js

Jan 6th, 2019
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client();
  3. const config = require("./config.json");
  4. const YTDL = require("ytdl-core")
  5. const fs = require("fs")
  6. var servers = {};
  7.  
  8. function play(connection,message){
  9.   var server = servers[message.gulid];
  10.  
  11.   server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter: "audioonly"}));
  12.   server.queue.shift();
  13.   server.dispatcher.on("end",function(){
  14.     if (server.queue[0])play(connection, message);
  15.     else
  16.     connection.disconnect();
  17.   });
  18. }
  19.  
  20. client.on('ready', () => {
  21.   console.log(`Logged in as ${client.user.tag}!`);
  22. });
  23.   client.on("error", (e) => console.error(e));
  24.   client.on("warn", (e) => console.warn(e));
  25.   client.on("debug", (e) => console.info(e));
  26. //  client.on("raw",(e) => console.raw(e));
  27. client.on("message", message => {
  28.   if (message.author.bot) return;
  29.   // This is where we'll put our code.
  30.   if (message.content.indexOf(config.prefix) !== 0) return;
  31.  
  32.   const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  33.   const command = args.shift().toLowerCase();
  34.  
  35.   if(command === 'ping') {
  36.     message.channel.send('Pong!');
  37.   } else
  38.   if (command === 'blah') {message.channel.send('Meh.');}
  39.  else
  40.   if (command === 'music') {
  41.     if (args[0] === "play"){if(message.member.voiceChannel){message.member.voiceChannel.join().then(connect => {message.reply("I have connect to the voiceChannel");}).then(function (connection){play(connection,message);});}else{message.reply("You need to join a first !!!");}}
  42.     else
  43.     if (args[0] === "join"){if(message.member.voiceChannel){message.member.voiceChannel.join().then(connect => {message.reply("I have connect to the voiceChannel");}).catch(console.log);}else{message.reply("You need to join a first !!!");}}
  44.     else
  45.     if (args[0] === "leave"){if(message.member.VoiceChannel){client.voiceChannel.leave();}else{message.reply("I need to be in the voice channel first");}}
  46.     else
  47.     if (args[0] === "stop"){message.channel.send("stop function comming soon");}
  48.     else
  49.     if (args[0] === "pause"){message.channel.send("pause function comming soon");}
  50.     else
  51.     message.channel.send("command: play pause stop join leave");
  52. }
  53. if (message.content.includes('changeNick')) {
  54.     client.setNickname({nick: message.content.replace('changeNick ', '')});
  55. }
  56. if (command === "asl") {
  57.   let [age, sex, location] = args;
  58.   message.reply(`Hello ${message.author.username}, I see you're a ${age} year old ${sex} from ${location}. Wanna date ?`);
  59.  
  60. }
  61. // Kick a single user in the mention
  62. if (command === "kick") {
  63.  let member = message.mentions.members.first();
  64.  member.kick();
  65. }
  66.  //Ensures bot doesn't reply to itself or non-commands
  67.   if (message.author.bot) return;
  68. //  if (!message.content.startsWith(config.prefix)) return;
  69.  
  70.   //Simplifies command making
  71. //  let command = message.content.toLowerCase().split(" ")[0];
  72. //  command = command.slice(config.prefix.length);
  73.  
  74.   //Simplifies arguments in a command
  75.   //  let args = message.content.split(" ").slice(1);
  76.  
  77.   if (command === "changeNick") {
  78.   let [name] = args;
  79.     client.user.setUsername(args).then(user => message.reply(`My new nickname is ${user.username}!`)).catch(console.error);
  80.  
  81.   }
  82.   if(command === "say"){
  83.   let text = args.join(" ");
  84.   message.delete();
  85.   message.channel.send(text);
  86. }
  87.  if(command === "bot"){
  88.     if(args[0] === "shutdown"){message.channel.send('shutting down').then(msg => client.destroy())};
  89.     if(args[0] === "restart"){message.channel.send('Restartting...').then(msg => client.destroy()).then(()=> client.login(config.token));}}
  90. //if(command === "quote") {
  91. //  const [channelid, messageid, quotename, ...note] = args.splice(1);
  92.   // I also support "here" as a channelID using this:
  93. //  const channel = channelid == "here" ? message.channel : client.channels.get(channelid);
  94.   // I do the same with message ID, which can be "last":
  95. //  const message = messageid === "last" ? msg.channel.messages.last(2)[0] : await channel.messages.get(messageid);
  96.   // pretend for a second this is the rest of the function:
  97. //  insertInDB(quotename, channel.id, message.id, note.join(" "));
  98. //}
  99. });
  100. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement