Although noblox.js will get the job done fine, there is a newer library that has arguably better code structure and uses the latest APIs (I’m pretty sure noblox still uses a few outdated APIs, but don’t quote me on that).
module.exports.run = async (bot, message, args) => {
let username = args[0]
if (username) {
roblox.getIdFromUsername(username).then(id => { // gets user id for the specific part of the embed
if (id) {
roblox.getPlayerInfo(parseInt(id)).then(function(info) {
let date = new Date(info.joinDate) // states join date
let dateInfo = bot.extractDate(date)
let embed = new discord.RichEmbed() // starts a new embed
.setColor("#f9ae00") // sets the color of the embed
.setURL(`https://roblox.com/users/${id}/profile`) // base link, changed by the variables 'id'
.setTimestamp()
.setThumbnail(`https://www.roblox.com/bust-thumbnail/image?userId=${id}&width=420&height=420&format=png`) // gets the roblox profile picture
.addField("Username", info.username || 'Unresolvable', true) // everything in the embed is undefined, therefore can be changed by the variables
.addField("User ID", id || 'Unresolvable', true)
.addField("Blurb", info.blurb || 'Nothing', true)
.addField("Status", info.status || 'Nothing', true)
.addField("Account Age", `${info.age} days old` || 'Unresolvable')
.addField("Register Date", `${dateInfo.month}/${dateInfo.day}/${dateInfo.year}` || 'Unresolvable')
.addField("User Link", `https://roblox.com/users/${id}/profile`)
.setFooter(`Powered By DEMOLURKS tutorial.`, bot.user.avatarURL)
message.channel.send({embed})
})
}
}).catch(function (err) {
message.channel.send("Sorry, that user doesn't seem to exist, double check your spelling and try again!") // catching error
});
} else {
message.channel.send("Please provide a valid username, e.g. '-search ROBLOX'.")
}
}
module.exports.help = {
name: "search" // command name
}
The command is well done but I think you should add a catch function to roblox.getPlayerInfo as well. If the user you try to search is banned, it will throw an error.