Ledger Nano X - The secure hardware wallet
SHARE
TWEET

save roles

MrWolf_1sT May 22nd, 2020 986 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const members = JSON.parse(fs.readFileSync("./members.json")) || {};
  2. client.on('ready', () => {
  3.   console.log(`Logged in as ${client.user.tag}!`);
  4.   client.guilds.forEach(g=> !members[g.id] ? members[g.id] = {} : null)
  5. });
  6.  
  7. client.on("guildMemberRemove", member=>{
  8.   let roles = [];
  9.   member.roles.forEach(r=> roles.push(r.id));
  10.   members[member.guild.id][member.id] = roles;
  11.   saveChanges();
  12. });
  13. client.on("guildMemberAdd", member=> {
  14.   if(members[member.guild.id][member.id] !== undefined){
  15.     member.addRoles(members[member.guild.id][member.id], "Returning roles after leaving");
  16.     members[member.guild.id][member.id] = [];
  17.   };
  18.   saveChanges();
  19. });
  20. function saveChanges(){
  21.   fs.writeFileSync("./members.json", JSON.stringify(members, null, 4));
  22. };
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