await only valid with async function urban dictionary api discord js

Any idea how i can fix this problem? I tried putting an async function in and I couldn’t get it to work. I’m not quite sure on how or where to add the async function, and how to get the two to work together. Any help is much appreciated, and this is for a discord javascript bot.

client.on('message', 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);
}
});

25 thoughts on “await only valid with async function urban dictionary api discord js”

  1. 394913 687176hello!,I genuinely like your writing very a good deal! percentage we maintain up a correspondence extra about your post on AOL? I need an expert on this area to unravel my difficulty. May be that is you! Taking a look forward to peer you. 235734

    Reply

Leave a Comment