Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. const roblox = require('roblox-js')
  2. const discord = require('discord.js')
  3. const token = process.env.token;
  4. var client = new discord.Client();
  5. var prefix = '/';
  6. var groupId = 4040978;
  7. var maximumRank = 13;
  8.  
  9. var username = process.env.token;
  10. var password = process.env.token;
  11.  
  12. client.login(token)
  13.  
  14. // LOGIN FUNCTION
  15. function login() {
  16. return roblox.login(username, password);
  17. }
  18.  
  19. login() // Log into ROBLOX
  20. .then(function() { // After the function has been executed
  21. console.log('Logged in.') // Log to the console that we've logged in
  22. })
  23. .catch(function(error) { // This is a catch in the case that there's an error. Not using this will result in an unhandled rejection error.
  24. console.log(`Login error: ${error}`) // Log the error to console if there is one.
  25. });
  26.  
  27. function isCommand(command, message){
  28. var command = command.toLowerCase();
  29. var content = message.content.toLowerCase();
  30. return content.startsWith(prefix + command);
  31. }
  32.  
  33.  
  34. client.on('message', (message) => {
  35. if (message.author.bot) return; // Dont answer yourself.
  36. var args = message.content.split(/[ ]+/)
  37.  
  38. if(isCommand('rank', message)){
  39. if(!message.member.roles.some(r=>["High Ranks"].includes(r.name)) ) // OPTIONAL - Checks if the sender has the specified roles to carry on further
  40. return message.reply("You can't use this command.");
  41. var username = args[1]
  42. var rankIdentifier = Number(args[2]) ? Number(args[2]) : args[2];
  43. if (!rankIdentifier) return message.channel.send("Please enter a rank");
  44. if (username){
  45. message.channel.send(`Checking ROBLOX for ${username}`)
  46. roblox.getIdFromUsername(username)
  47. .then(function(id){
  48. roblox.getRankInGroup(groupId, id)
  49. .then(function(rank){
  50. if(maximumRank <= rank){
  51. message.channel.send(`${id} is rank ${rank} and not promotable.`)
  52. } else {
  53. message.channel.send(`${id} is rank ${rank} and promotable.`)
  54. roblox.setRank(groupId, id, rankIdentifier)
  55. .then(function(newRole){
  56. message.channel.send(`Changed rank to ${newRole.Name}`)
  57. }).catch(function(err){
  58. console.error(err)
  59. message.channel.send("Failed to change rank.")
  60. });
  61. }
  62. }).catch(function(err){
  63. message.channel.send("Couldn't get that player in the group.")
  64. });
  65. }).catch(function(err){
  66. message.channel.send(`Sorry, but ${username} doesn't exist on ROBLOX.`)
  67. });
  68. } else {
  69. message.channel.send("Please enter a username.")
  70. }
  71. return;
  72. }
  73. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement