简体   繁体   English

SyntaxError: await 仅在我的代码中的异步 function 中有效

[英]SyntaxError: await is only valid in async function in my code

I have problem with my code, the error is SyntaxError: await is only valid in async function.我的代码有问题,错误是SyntaxError: await is only valid in async function.

const Discord = require("discord.js")

module.exports = {
  name: "ping",
  description: "Display ping latency.",

  run(msg, args) {
    let waiting = await message.channel.send("Calculation...").catch(console.error)

    let embed = new Discord.MessageEmbed()

      .setTitle("Bot & Discord.js API latency", bot.user.avatarURL)
      .setColor(0xb348ff)
      .setField("BOT :", "> '" + '${waiting.createdTimestamp - message.createdTimestamp}' + "ms'", true)
      .setField("API :", "'" + Math.round(bot.ping) + "ms'", true)
      .setTimestamp(message.createdAt)
      .setTimestamp()

    waiting.edit(embed).catch(console.error)
  }
}

The error says it all, you can only use await inside of an asynchronous ( async ) function.错误说明了一切,您只能在异步( async )function 中使用await

const Discord = require("discord.js")

module.exports = {
  name: "ping",
  description: "Display ping latency.",

  async run(msg, args) {
    let waiting = await message.channel.send("Calculation...").catch(console.error)

    let embed = new Discord.MessageEmbed()

      .setTitle("Bot & Discord.js API latency", bot.user.avatarURL)
      .setColor(0xb348ff)
      .setField("BOT :", "> '" + '${waiting.createdTimestamp - message.createdTimestamp}' + "ms'", true)
      .setField("API :", "'" + Math.round(bot.ping) + "ms'", true)
      .setTimestamp(message.createdAt)
      .setTimestamp()

    waiting.edit(embed).catch(console.error)
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Appium 代码生成“SyntaxError: await is only valid in async function” - Appium code generates "SyntaxError: await is only valid in async function" Javascript:SyntaxError:await仅在异步函数中有效 - Javascript: SyntaxError: await is only valid in async function 为什么我的 await 在我的功能中不起作用? “语法错误:等待仅在异步函数中有效” - Why is my await not working in my funciton? "SyntaxError: await is only valid in async function" 未捕获的SyntaxError:await仅在异步函数的异步函数中有效 - Uncaught SyntaxError: await is only valid in async function in async function SyntaxError: await 仅在异步中有效 function **而且我有异步** - SyntaxError: await is only valid in async function **and I have async** 语法错误:await 仅在异步函数 discord.js 中有效 - SyntaxError: await is only valid in async function discord.js SyntaxError: await 仅在 async 函数中有效。 无法纠正 - SyntaxError: await is only valid in async function. Unable to Correct it Node Js - SyntaxError: await 仅在异步中有效 function - Node Js - SyntaxError: await is only valid in async function SyntaxError:“await”仅在“async”中有效 function - 需要帮助 - SyntaxError: “await” is only valid in an “async” function - Help Needed 未捕获的 SyntaxError:await 仅在异步函数中有效(FireBase 文档) - Uncaught SyntaxError: await is only valid in async function (FireBase documentation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM