Trikz
Trikz

Reputation: 45

Do not know how to async this

I have listed everything to do with this command ive been working on and this is the error it returns with, i wanted to test if the finding pictures thing work but it just returns with

SyntaxError: await is only valid in async function
    at wrapSafe (internal/modules/cjs/loader.js:1047:16)
    at Module._compile (internal/modules/cjs/loader.js:1097:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

I do understand the problem but i do not know how to async, pls help <3

   const superagent = require("superagent");

bot.on('message', message => {

    let args = message.content.substring(PREFIX.length).split(" ");

         case 'cat':
                let message = await message.channel.send("Finding Cat Pictures...")

                let {body} = await superagent
                .get('https://aws.random.cat/meow')
                console.log(body.file)

Upvotes: 2

Views: 52

Answers (1)

Syntle
Syntle

Reputation: 5174

Just make the function async

bot.on('message', async message => {

    let args = message.content.substring(PREFIX.length).split(" ");

         case 'cat':
                let message = await message.channel.send("Finding Cat Pictures...")

                let {body} = await superagent
                .get('https://aws.random.cat/meow')
                console.log(body.file)

Upvotes: 2

Related Questions