![](/img/trans.png)
[英]Javascript: SyntaxError: await is only valid in async function
[英]SyntaxError: await is only valid in async function?
我在js(節點js)中編碼,當我啟動我的機器人時出現這個錯誤。 任何人都可以幫助我嗎?
let ip = arg.split(":")[0];
let port = arg.split(":")[1];
let imgRes = await fetch("https://www.minecraftskinstealer.com/achievement/a.php?i=2&h=Success&t="+ip);
let imgAttachment = new Discord.MessageAttachment(await imgRes.buffer(), "success.png");
var serveurinfo = new Discord.RichEmbed()
.setAuthor(message.author.username , message.author.avatarURL)
.setColor("RANDOM")
.setTitle("Information du serveur MCPE\n")
.setDescription("Information du serveur:\n" + ip + " | " + port)
.addField("Il y a (" + state.raw.numplayers + "/" + state.raw.maxplayers + ")" + " Joueurs en ligne.\n\n", onlinePlayers)
.addField("Version", state.raw.version)
.addField("Ping", state.ping + "ms")
.setImage("https://cdn.discordapp.com/attachments/262263759685287939/596993744700440576/skytaria.png")
message.channel.send([ serveurinfo, imgAttachment ]);```
您需要使用 async 函數包裝 await 語句;
const results = async function(){
return await fetch("https://www.minecraftskinstealer.com/achievement/a.php?i=2&h=Success&t="+ip);
let imgAttachment = new Discord.MessageAttachment(await imgRes.buffer(), "success.png");
var serveurinfo = new Discord.RichEmbed()
.setAuthor(message.author.username , message.author.avatarURL)
.setColor("RANDOM")
.setTitle("Information du serveur MCPE\n")
.setDescription("Information du serveur:\n" + ip + " | " + port)
.addField("Il y a (" + state.raw.numplayers + "/" + state.raw.maxplayers + ")" + " Joueurs en ligne.\n\n", onlinePlayers)
.addField("Version", state.raw.version)
.addField("Ping", state.ping + "ms")
.setImage("https://cdn.discordapp.com/attachments/262263759685287939/596993744700440576/skytaria.png")
message.channel.send([ serveurinfo, imgAttachment ])
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.