UNPKG

dthings-api

Version:

Get information users and bots from discordthings.com

21 lines (15 loc) 729 B
const { load } = require("cheerio") const request = require("request-promise") const { getInfoBot } = require("./getInfoBot.js") module.exports.searchBot = async (name=String) => { if(typeof name !== "string") throw new TypeError("The name must be a string") if(name.match(/\d{17,19}/g)) throw new TypeError("The name cannot be an id") let $ = await request({ uri: `https://discordthings.com/search?q=${name.replace(/[^a-zA-z0-9 ]/g, "").replace(" ", "+")}&page=1`, transform: body => load(body) }) if($(".text-muted.text-bold").html()) throw new Error("Results 0") let id = $(".dthings-card__flex__image").attr("style").match(/\d{17,19}/g)[0] let info = await getInfoBot(id) return info }