Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var discord = require('discord.js');
- var roblox = require('roblox-js');
- var client = new discord.Client();
- var token = ""
- client.on('guildMemberAdd', member => {
- let guild = member.guild;
- let user = member.user
- console.log(`${user.tag} joined ${guild}`)
- });
- client.on('guildMemberRemove', member => {
- let guild = member.guild;
- let user = member.user
- console.log(`${user.tag} left ${guild}`)
- });
- var prefix = '-';
- var groupId = 4232087;
- var maximumRank = 140;
- function isCommand(command, message){
- var command = command.toLowerCase();
- var content = message.content.toLowerCase();
- return content.startsWith(prefix + command);
- }
- client.on('message', (message) => {
- if (message.author.bot) return; // Dont answer yourself.
- var args = message.content.split(/[ ]+/)
- if(isCommand('setRank', message)){
- if (message.author.id !== '238419054581252096' && message.author.id !== '249266594461515776' && !message.member.roles.get('462961781564768278')) return message.reply("you do not have permission to use that command")
- var username = args[1]
- var rankIdentifier = Number(args[2]) ? Number(args[2]) : args[2];
- if (!rankIdentifier) return message.channel.send("Please enter a rank");
- if (username){
- message.channel.send(`Checking ROBLOX for ${username}`)
- roblox.getIdFromUsername(username)
- .then(function(id){
- roblox.getRankInGroup(groupId, id)
- .then(function(rank){
- if(maximumRank <= rank){
- message.channel.send(`${id} is rank ${rank} and not promotable.`)
- } else {
- message.channel.send(`${id} is rank ${rank} and promotable.`)
- roblox.setRank(groupId, id, rankIdentifier)
- .then(function(newRole){
- message.channel.send(`Changed rank to ${newRole.Name}`)
- }).catch(function(err){
- console.error(err)
- message.channel.send("Failed to change rank.")
- });
- }
- }).catch(function(err){
- message.channel.send("Couldn't get him in the group.")
- });
- }).catch(function(err){
- message.channel.send(`Sorry, but ${username} doesn't exist on ROBLOX.`)
- });
- } else {
- message.channel.send("Please enter a username.")
- }
- return;
- }
- if (isCommand('transfer', message)) {
- var oldGroup = 2710984
- var newGroup = 4234366
- var scope = args[1];
- if (!scope) scope = 'all';
- else var username = scope;
- if (scope.toLowerCase() === 'all') {
- if (message.author.id !== '238419054581252096') return message.reply("you do not have permission to use that command")
- message.channel.send("Fetching players")
- return roblox.getPlayers(newGroup)
- .then(function(group){
- message.channel.send("Transferring")
- for (let player of group.players){
- roblox.getRankInGroup(oldGroup, player.id)
- .then(function(rank){
- if (rank < maximumRank && rank > player.parent.role.Rank && rank !== player.parent.role.Rank) {
- roblox.setRank(newGroup, player.id, rank)
- .then(function(newRole){
- message.author.send("Set " + player.name + "'s rank to " + newRole.Name)
- });
- }
- });
- }
- }).catch(function(err){
- console.error(err)
- message.channel.send("Failed to transfer.")
- });
- } else {
- message.channel.send(`Checking ROBLOX for ${username}`)
- return roblox.getIdFromUsername(username)
- .then(function(id){
- return roblox.getRankInGroup(oldGroup, id)
- .then(function(rank){
- if (rank >= maximumRank) return message.channel.send(`${id} is rank ${rank} in old group and not promotable.`);
- return roblox.setRank(newGroup, id, rank)
- .then(function(newRole){
- return message.channel.send(`Changed rank to ${newRole.Name} in new group`)
- })
- .catch(function(err) {
- console.error(err)
- message.channel.send("Failed to change rank.")
- })
- }).catch(function(err){
- message.channel.send("Couldn't get him in the group.")
- });
- }).catch(function(err){
- message.channel.send(`Sorry, but ${username} doesn't exist on ROBLOX.`)
- });
- }
- }
- });
- client.login(token)
- roblox.login({username: "", password: ""}).then((success) => {
- }).catch(() => {console.log("Sorry, it failed.");});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement