killerbrenden

SetRank

May 15th, 2020
143
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 nbx = require('noblox.js')
  4. const token = "This is filled in my code"
  5. const prefix = "?"
  6. const groupid = 5476584
  7. const maxRank = 250
  8. const cookie = "This is filled in my code"
  9. const minRank = 1
  10. const shoutRank = 11
  11.  
  12. function isCommand(command,message){
  13.     const cmd = command.toLowerCase()
  14.     const content = message.content.toLowerCase()
  15.     return content.startsWith(prefix + cmd)
  16. };
  17.  
  18. client.on('message', message => {
  19.     if (message.author.bot) return;
  20.     if (!message.content.startsWith(prefix)) return;
  21.  
  22.     var args = message.content.split(/[ ]+/)
  23.  
  24.     if (isCommand('Setrank', message)){
  25.         var username = args[1]
  26.         let userLen = username.length
  27.         var typeRank = message.content.slice(userLen + 10, 2000)
  28.  
  29.         if (Number(typeRank)){
  30.             typeRank = Number(typeRank)
  31.         } else {
  32.             message.channel.send("Please use the Rank Number to change their rank!")
  33.         }
  34.  
  35.         if (username){
  36.             nbx.getIdFromUsername(username)
  37.             .then(function(id){
  38.                 nbx.getRankInGroup(groupid,id)
  39.                 .then(function(grank){
  40.                     if (grank >= maxRank){
  41.                         message.channel.send("This user's rank is already at the highest rank! Their rank has to be changed manually!")
  42.                     } else {
  43.                         if (typeRank) {
  44.                             nbx.setRank({group: groupid, target: id, rank: typeRank})
  45.                             .then(function(roles){
  46.                                 message.channel.send("New Rank: " + typeRank)
  47.                             }).catch(function(error){
  48.                                 message.channel.send("That Role Does Not Exist!")
  49.                                 console.log(error);
  50.                             })
  51.                         } else {
  52.                             message.channel.send("Make Sure The Rank Name Exists And Is A Name!")
  53.                         }
  54.                     }
  55.                 }).catch(function(error){
  56.                     message.channel.send("That User Is Not In The Group!")
  57.                     console.log(error);
  58.                 })
  59.             }).catch(function(error){
  60.                 message.channel.send("That User Does Not Exist!")
  61.                 console.log(error);
  62.             })
  63.         }
  64.     }
  65. }
Add Comment
Please, Sign In to add comment