sentanos / roblox-js

!!!THIS PROJECT IS NO LONGER MAINTAINED!!! Execute ROBLOX website actions in node.js
MIT License
45 stars 45 forks source link

Trying to obtain a user id by var and it says user not found #101

Open BleachPoptart opened 6 years ago

BleachPoptart commented 6 years ago

var dateFormat = require('dateformat'); var now = new Date(); var variable = message.content.replace(';exile', ''); var ID = rbx.getIdFromUsername(variable); if(message.member.roles.some(r=>["Specialized Control Unit", "Combat Medic Leader", "Officer", "Lieutenant", "Captain", "Assistant Director", "Director", "Overseer", "The Administrator"].includes(r.name)) ) { console.log('Waiting for login.') rbx.login('username', 'my password'); console.log('Login verifed.') console.log(message.author.username + ' Has logged into SCPF_SECURITYDEPT At ' + dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT")) setTimeout(function(){ rbx.exile(3506926,ID); }, 10000); console.log(message.author.username + ' Has exiled ' + variable, ' from the Security Department At ' + dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT")) message.channel.send(message.author + ' Has exiled' + variable,' from the Security Department At' + dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT"))} else{ message.channel.send("Exile failed, Do you have the correct role to use this function?") console.log(message.author.username + ' Has attempted to exile' + variable + ' at' + dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT"))} break;

suufi commented 6 years ago

rbx.getIdFromUsername() returns a promise. Read this article: https://anidiots.guide/other-guides/async-await to understand a bit more about Promises. Consider using async/await or the classic .then statements. One other small thing, I do not recommend writing code like this. Use some kind of command module framework like Discord.js-commando.