Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. const discord = require("discord.js");
  2. const fs = require("fs");
  3. const config = require("./config.json");
  4. const token = require("./token.json").token;
  5. const bot = new discord.Client({
  6.   disableEveryone: true
  7. });
  8.  
  9. // When bot ready
  10. bot.on("ready", async () => {
  11.   console.log(`${bot.user.username} is ready for action!`);
  12.   if (config.activity.streaming == true) {
  13.     bot.user.setActivity(config.activity.game, {
  14.       url: 'https://twitch.tv/username'
  15.     });
  16.   } else {
  17.     bot.user.setActivity(config.activity.game, {
  18.       type: 'LISTENING'
  19.     }); //PLAYING, LISTENING, WATCHING
  20.     bot.user.setStatus('idle'); // dnd, idle, online, invisible
  21.   }
  22. });
  23.  
  24. client.on("guildCreate", guild => {
  25.   guild.createChannel('rules','text')
  26. })
  27. // Load commands
  28. bot.commands = new discord.Collection();
  29. fs.readdir("./commands/", (err, files) => {
  30.   if (err) console.error(err);
  31.   let jsfiles = files.filter(f => f.split(".").pop() === "js");
  32.  
  33.   if (jsfiles.length <= 0) return console.log("There are no commands to load...");
  34.  
  35.   console.log(`Loading ${jsfiles.length} commands...`);
  36.   jsfiles.forEach((f, i) => {
  37.     let props = require(`./commands/${f}`);
  38.     console.log(`Command Number ${i + 1}, With the name ${f} has succesfully loaded loaded!`);
  39.     bot.commands.set(props.help.name, props);
  40.   });
  41. });
  42.  
  43. // Message event
  44. bot.afk = new Map();
  45. bot.on("message", async message => {
  46.   if (message.author.bot) return;
  47.   if (message.channel.type === "dm") return;
  48.  
  49.   let prefix = config.prefix;
  50.   let messageArray = message.content.split(" ");
  51.   let command = messageArray[0].toLowerCase();
  52.   let args = messageArray.slice(1);
  53.  
  54.   if (message.content.includes(message.mentions.users.first())) {
  55.     bot.afk.forEach(key => {
  56.       if (key.id == message.mentions.users.first().id) {
  57.         message.guild.fetchMember(key.id).then(member => {
  58.           let user_tag = member.user.tag;
  59.           return message.channel.send(`**${user_tag}** is currently afk. Reason: ${key.reason}`);
  60.         });
  61.       }
  62.     });
  63.   }
  64.  
  65.   bot.afk.forEach(key => {
  66.     if (message.author.id == key.id) {
  67.       bot.afk.delete(message.author.id);
  68.       return message.reply(`You have been removed from the afk list!`).then(msg => msg.delete(5000));
  69.     }
  70.   });
  71.  
  72.   if (!command.startsWith(prefix)) return;
  73.  
  74.   let cmd = bot.commands.get(command.slice(prefix.length));
  75.   if (cmd) cmd.run(bot, message, args);
  76. });
  77.  
  78. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement