Guest User

Untitled

a guest
Nov 17th, 2019
111
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 YTDL = require("ytdl-core");
  4. const fs = require("fs");
  5. const config = require("./config.json");
  6. const prefix = config.prefix;
  7. let saycommandusage = [];
  8. var buylist = [];
  9. var servers = {};
  10. function verify(id){
  11. for(var i = 0;i<config.botAdminID;i++){
  12. if(id==config.botAdminID[i]){
  13. return true;
  14. }else{
  15. return false;
  16. }
  17. }
  18. }
  19. function makeAllChannel(msg){
  20. msg.guild.createChannel("welcome",'text');
  21. msg.guild.createChannel("index-dot-html", 'text')
  22. msg.guild.createChannel("rules-n-info", 'text')
  23. msg.guild.createChannel("announcements", 'text')
  24. msg.guild.createChannel("chat", 'text')
  25. msg.guild.createChannel("help", 'text')
  26. msg.guild.createChannel("team-building", 'text')
  27. msg.guild.createChannel("song-requests", 'text')
  28. msg.guild.createChannel("bot-commands", 'text')
  29. msg.guild.createChannel("music", 'voice')
  30. msg.guild.createChannel("memes", 'text')
  31. }
  32. function reactH(message){
  33. return message.reactions;
  34. }
  35.  
  36. function play(connection,message){
  37. try {
  38. var server = servers[message.guild.id];
  39. var songInfo = YTDL.getInfo(server.queue[0]);
  40. var song = {
  41. title: songInfo.title,
  42. url: songInfo.video_url,
  43. };
  44. console.log(songInfo)
  45. server.dispatcher = connection.playStream(YTDL(server.queue[0],{filter:"audioonly"}));
  46. server.queue.shift();
  47. server.dispatcher.on("end", function(){
  48. if(server.queue[0]) play(connection,message);else{
  49. connection.disconnect();
  50. message.channel.send("song ended");
  51. }
  52. });
  53. }
  54. catch (err){
  55. message.channel.send("Make sure you are using a youtube url and the correct format. Try again.");
  56. var server = servers[message.guild.id];
  57. if(message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  58. message.channel.send("stopping music...");
  59. server.queue=[];
  60. }
  61. }
  62. client.on("ready", () => {``
  63. client.user.setActivity(` on ${client.guilds.size} servers. (prefix:"`+config.prefix+`")`);
  64. console.log(`Ready to serve on ${client.guilds.size} servers, for ${client.users.size} users.`);
  65. });
  66. client.on("guildMemberAdd", (member) => {
  67. try{
  68. console.log(`New User "${member.user.username}" has joined "${member.guild.name}"` );
  69. member.guild.channels.find(c => c.name === "welcome").send(`"${member.user.username}" has joined this server`);
  70. }
  71. catch(err){
  72. console.log("missing welcome chat")
  73. }
  74. });
  75. /*
  76. client.on("guildCreate", guild =>{
  77. var msg = member.guild.channels.get("general").send(`hello! react with :white_check_mark: or :x: to set up hackathon discord.`);
  78. msg.react(':white_check_mark:').then(()=> message.react(':x:'));
  79. var modConf = true;
  80. while(modConf){
  81. var rAr = setTimeout(reactH(msg), 1000);
  82. var rAr = rAr.array()
  83. for(i in rAr){
  84. if (typeof i == "MessageReaction" && (i.name=="white_check_mark" || i.name=="x")){
  85. for(j in i.users){
  86.  
  87. }
  88. }
  89. }
  90. }
  91. })
  92. */
  93. client.on("message", (message) => {
  94. if (!message.content.startsWith(prefix) || message.author.bot) return;
  95. const args = message.content.slice(prefix.length).trim().split(/ +/g);
  96. const command = args.shift().toLowerCase();
  97. if(command==="play"){
  98. if(!args[0]){
  99. message.channel.send("Please specify what you want played.");
  100. }else{
  101. if(!message.member.voiceChannel){
  102. message.channel.send("Please join a voice channel for music to play");
  103. }else{
  104. if(!servers[message.guild.id]) servers[message.guild.id]={
  105. queue :[]
  106. };
  107. var server = servers[message.guild.id];
  108. server.queue.push(args[0]);
  109. if(!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection){
  110. message.channel.send("Playing...");
  111. play(connection,message)
  112. });
  113. }
  114. }
  115. }
  116. if(command==="skip"){
  117. var server = servers[message.guild.id];
  118. message.channel.send("Skipping...");
  119. if(server.dispatcher) server.dispatcher.end();
  120. }
  121. if(command==="stop"){
  122. var server = servers[message.guild.id];
  123. if(message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  124. message.channel.send("music stopping...");
  125. }
  126. if(command==="crash"){
  127. if(message.author.id === config.botAdminID[0]){
  128. crash();
  129. }else{
  130. message.reply("you cant because you are not an owner");
  131. }
  132. }
  133. if(command==="clearChannel"||command==="purge"||command==="clear"){
  134. try{
  135. if(message.author.id === config.ownerID || message.channel.permissionsFor(message.author).has("MANAGE_MESSAGES")){
  136. if(args[0]==="all"){
  137. for(var i = 0;i<10;i++){
  138. message.channel.bulkDelete(99)
  139. }
  140. }else if(args[0]<100){
  141. message.channel.bulkDelete(args[0])
  142. .then(messages => message.channel.send(`Deleted ${messages.size} messages`))
  143. .catch( error => message.channel.send("cannot delete message over 14 days old.(or i dont have the perms)"))
  144. }else{
  145. message.channel.sendMessage("specify how much deleted and it must be less than 100 messages at a time");
  146. }
  147. }
  148. }
  149. catch(err){
  150. message.channel.sendMessage("likely missing permissions");
  151. }
  152. }
  153. if(command==="setup"){
  154. if(!args[0]){
  155. message.reply("specify which setup part you want");
  156. }else{
  157. if(args[0]==="all"){
  158. makeAllChannel(message)
  159. message.reply("done! text channels and voice channels created!");
  160. }
  161. }
  162. }
  163. if(command==="alert"){
  164. if(!args[0] || !args[1] || !args[2]){
  165. message.reply("usage: alert [name of hackathon] [hackathon region] [hackathon date]");
  166. }else{
  167. message.reply("are you sure you want to post "+args[0]+" for the "+args[1]+" on "+args[2]+"?");
  168. }
  169. }
  170. if(command==="createchannel"){
  171. if(args[0]){
  172. message.guild.createChannel(args[0], 'text')
  173. message.reply("done! text channel "+args[0]+" created!");
  174. }
  175. }
  176. });
  177. client.login(config.token);
RAW Paste Data