In order to run your await
command, you have to put async
at the top of your code. For more info about how await
and async
work, look at the link provided by VLAZ.
//put the async right before the second message, that's it
client.on('message', async message => {
if (message.content.startsWith(`${PREFIX}urban`)) {
if (!args.length) {
return message.channel.send('You need to supply a search term!');
}
const query = querystring.stringify({ term: args.join(' ') });
const { list } = await fetch(`https://api.urbandictionary.com/v0/define?${query}`).then(response => response.json());
if (!list.length) {
return message.channel.send(`No results found for **${args.join(' ')}**.`);
}
const [answer] = list;
const embed = new Discord.MessageEmbed()
.setColor('#EFFF00')
.setTitle(answer.word)
.setURL(answer.permalink)
.addFields(
{ name: 'Definition', value: trim(answer.definition, 1024) },
{ name: 'Example', value: trim(answer.example, 1024) },
{ name: 'Rating', value: `${answer.thumbs_up} thumbs up. ${answer.thumbs_down} thumbs down.` },
);
message.channel.send(embed);
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…