不知道如何异步这个

我已经列出了我一直在处理的与此命令有关的所有内容,这是它返回的错误,我想测试查找图片是否有效,但它只是返回


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

我确实理解这个问题,但我不知道如何异步,请帮助 <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)


杨魅力
浏览 70回答 1
1回答

阿晨1998

只做功能asyncbot.on('message', async message => {&nbsp; &nbsp; let args = message.content.substring(PREFIX.length).split(" ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'cat':&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let message = await message.channel.send("Finding Cat Pictures...")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let {body} = await superagent&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .get('https://aws.random.cat/meow')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(body.file)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript