[英]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.