Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(message.content.startsWith('!search')) {
- var args = message.content.split(' '); args.shift()
- var options = {
- url: "https://www.google.com/search?q=" + args.join(' '),
- method: "GET",
- headers: {
- "Accept": "text/html",
- "User-Agent": "Chrome"
- }
- };
- console.log(options.url)
- request(options, function(error, response, responseBody) {
- if (error) {
- console.log(error)
- return message.channel.send('An error has occured! Please tell the developer to check the console!')
- }
- $ = cheerio.load(responseBody);
- var links = $(".image a.link");
- var urls = new Array(links.length).fill(0).map((v, i) => links.eq(i).attr("href"));
- console.log(urls);
- if (!urls.length) {
- return;
- }
- // Send result
- message.channel.send( urls[Math.floor(Math.random() * urls.length)]);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement