Advertisement
Guest User

Search command.

a guest
May 12th, 2020
4,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // server.js
  2. // where this search bot's life starts.
  3. const prefix = process.env.prefix
  4.  
  5. // we're using the discord.js library here, along with noblox to get you started.
  6. // but feel free to add whichever libraries you please, mix and match them to make this application more powerful
  7. const discord = require("discord.js")
  8. const client = new discord.Client()
  9. const roblox = require("noblox.js")
  10.  
  11. // listening event for the search command to receive a prompt to seacrh
  12. client.on("message", message => {
  13.   const args = message.content.slice(prefix.length).split(' ');
  14.   const command = args.shift().toLowerCase();
  15.  
  16.   if (command === "search") {
  17.     let username = args[0]
  18.    
  19.     // if a username is supplied successfully
  20.     if (username) {
  21.         roblox.getIdFromUsername(username).then(id => {
  22.          
  23.           // if an identity is found under the username then continue collecting the rest of the data
  24.           // sadly this means you can't search for banned users. f in the chat. maybe try using older apis
  25.           // yes, i just did c# styled bracketing, do not mind me trying to bless your eyes
  26.          
  27.           if (id)
  28.  
  29.           {
  30.             // next conditio
  31.             roblox.getPlayerInfo(parseInt(id)).then(function(info)
  32.  
  33.             {
  34.               // dates.. um. go try get a pear or a grape instead.
  35.               let date = new Date(info.joinDate)
  36.               let dateInfo = client.extractDate(date)
  37.              
  38.               // create new embed and establish some settings for it, tasty.
  39.               let embed = new discord.RichEmbed()
  40.               .setColor("#FFFFFF")
  41.              
  42.               // the ${id} allows the id to change depending on user input
  43.               // so it pretty much allows you to search for any profile off the roblox.com website.
  44.               // neat, we've even got a thumbnail of the player available, if that wasn't enough information for you.
  45.               .setUrl(`https://roblox.com/users/${id}/profile`)
  46.               .setThumbnail(`https://www.roblox.com/bust-thumbnail/image?userId=${id}&width=420&height=420&format=png`)
  47.              
  48.               // more information, please senpai? you haven't given me anything :(
  49.               .addField("Username", info.username || 'Unresolvable', true)
  50.               .addField("User ID", id || 'Unresolvable', true)
  51.               .addField("Blurb", info.blurb || 'Nothing', true)
  52.               .addField("Status", info.status || 'Nothing', true)
  53.               .addField("Account Age", `${info.age} days old` || 'Unresolvable')
  54.               .addField("Register Date", `${dateInfo.month}/${dateInfo.day}/${dateInfo.year}` || 'Unresolvable')
  55.               .addField("User Link", `https://roblox.com/users/${id}/profile`)
  56.               .setFooter(`Search Bot`, client.user.avatarURL)
  57.               message.channel.send({embed})
  58.             })
  59.           }
  60.          
  61.        
  62.         // but what if the player is banned, or doesn't even exist?
  63.         // houston, we have a problem.
  64.         }).catch(function (err) {
  65.          message.channel.send("Sorry, that user doesn't seem to exist, double check your spelling and try again!") // catching error
  66.        });  
  67.     } else { message.channel.send("Please provide a valid username, e.g. '-search ROBLOX'.") }
  68.   }
  69. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement