return and await

This commit is contained in:
Daniel Odendahl Jr
2017-03-23 13:16:59 +00:00
parent cea110ce4b
commit 7c0a39ec5c
83 changed files with 295 additions and 264 deletions
+5 -4
View File
@@ -23,17 +23,18 @@ module.exports = class DefineCommand extends commando.Command {
}
console.log(`[Command] ${message.content}`);
let thingToSearch = encodeURI(message.content.split(" ").slice(1).join(" "));
message.channel.send('Searching...').then(msg => {
request
await message.channel.send('Searching...').then(msg => {
await request
.get(`https://www.google.com/search?q=${thingToSearch}`)
.then(function(response) {
const $ = cheerio.load(response.text);
let href = $('.r').first().find('a').first().attr('href');
if (!href) return Promise.reject(new Error('NO RESULTS'));
href = querystring.parse(href.replace('/url?', ''));
msg.edit(href.q);
return msg.edit(href.q);
}).catch(function(err) {
msg.edit(':x: Error! No Results Found!');
console.log(err);
return msg.edit(':x: Error! No Results Found!');
});
});
}