SHARE
TWEET

Untitled

a guest Mar 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!Client) {
  2.     var { Client } = require("discord.js");
  3. }
  4. if (!client) {
  5.     var client = new Client();
  6. }
  7. if (!fs) {
  8.     var fs = require("fs");
  9. }
  10. try {
  11.     require("./autorole.json");
  12. } catch (error) {
  13.     fs.writeFileSync("autorole.json", "{}");
  14. }
  15. if (!data) {
  16.     var data = require("./autorole.json");
  17. }
  18. function saveChanges() {
  19.     fs.writeFileSync("autorole.json", JSON.stringify(data));
  20. }
  21. client.on("message", async function (msg) {
  22.     if (!msg.author.bot) {
  23.         if (!prefix) {
  24.             var prefix = "-";
  25.         }
  26.         if (msg.content.startsWith(prefix)) {
  27.             var args = msg.content.slice(prefix.length).split(" ");
  28.             var command = args[0];
  29.             switch(command) {
  30.                 case "autorole":
  31.                     if (!msg.guild) return msg.reply("Nah");
  32.                     if (!msg.member.hasPermission("MANAGE_ROLES")) return msg.reply("You don't have enough permissions");
  33.                     if (!args[1]) return msg.reply("please mention the role");
  34.                     var role = msg.guild.roles.get(args[1]) || msg.mentions.roles.first() || msg.guild.roles.find(role => role.name.includes(args.slice(1).split(" "))) || msg.guild.roles.filter(role => role.name.includes(args.slice(1).split(" "))).first();
  35.                     if (!role) return msg.reply("please mention the role");
  36.                     msg.reply("Done");
  37.                     data[msg.guild.id] = role.id;
  38.                     saveChanges();
  39.                 break;
  40.             }
  41.         }
  42.     }
  43. })
  44. .on("guildMemberAdd", async function (member) {
  45.     if (data[member.guild.id]) {
  46.         if (member.guild.roles.get(data[member.guild.id])) {
  47.             try {
  48.                 member.addRole(member.guild.roles.get(data[member.guild.id]));
  49.             } catch (error) {
  50.                 console.error(error);
  51.             }
  52.         }
  53.     }
  54. })
  55. .login("NTAwOTMwMDY4NzkzNjU1Mjk2.D3j7dQ.o7Uhk66IuFbsvqGsbdRfs2FoxaM");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top