這與我的第一個問題有關。不知何故,我想我對我的代碼做了一些改進。
我更新了我所有的代碼。在我的 bot.js 中是:
require('dotenv').config();
let ver = process.env.DISCORD_BOT;
client.once("ready", async ()=> {
if(ver === "production") {
client.user.setActivity(`in code land`, {type: "PLAYING"});
}else{
client.user.setActivity(`over ${client.guilds.cache.size} server(s)`, {
type:"WATCHING",
status:"IDLE"
});
}
console.log(`Logged in as ${client.user.tag}!`);
console.log(`the prefix is ` prefix);
});
簡介:
worker: node bot.js
包.json:
"scripts": {
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1",
"production": "NODE_ENV=production&&npm start",
"development": "set NODE_ENV=development&&npm start"
}
.env:
DISCORD_BOT= TOKEN
當我檢查 heroku 應用程式日志時,它是這樣說的。
2021-12-22T03:13:05.436081 00:00 app[worker.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-12-22T03:13:05.436082 00:00 應用程式[worker.1]:^^^
2021-12-22T03:13:05.436082 00:00 應用程式[worker.1]:
2021-12-22T03:13:05.436082 00:00 app[worker.1]: SyntaxError: Unexpected token '??='
我搜索了一些關于 Unexpected token 的所有結果都是將 node.js 更新到 v16-17,但我已經在使用 Discord.js 和 Node.js 的最新版本。
uj5u.com熱心網友回復:
該錯誤來自 discord.js,這是因為您使用的是舊版本的 Node.js。的邏輯nullish賦值運算子(??=)是只在節點V15 可用。
您可能認為您使用的是最新版本的 Node.js,但 Heroku 說“如果引擎中未指定 Node 版本,則將使用 14.x 版本”。您可以engines在package.json檔案中添加一個prop 來指定您需要的版本。由于discord.js v13需要 node.js v16.6 ,您可以添加以下內容:
"engines": {
"node": "16.6"
}
或者要請求最新的 v16,請添加以下內容:
"engines": {
"node": "16.x"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/393362.html
