我正在嘗試使用 Heroku 和 Github 使我的不和諧機器人保持在線 24/7。但每當我嘗試運行我的代碼時,我都會收到此錯誤。
2022-01-01T03:56:43.950025 00:00 app[Worker.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2022-01-01T03:56:43.950043 00:00 app[Worker.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2022-01-01T03:56:43.950043 00:00 app[Worker.1]: ^^^
2022-01-01T03:56:43.950044 00:00 app[Worker.1]:
2022-01-01T03:56:43.950044 00:00 app[Worker.1]: SyntaxError: Unexpected token '??='
我在兩個位置放置了我的令牌,我在這些位置使用了 process.env.token。第一個是我的 index.js 檔案
(async () => {
for (file of functions) {
require(`./src/functions/${file}`)(client);
}
client.handleEvents(eventFiles, ".src/events");
client.handleCommands(commandFolders, "./src/commands");
client.login(process.env.token);
})();
第二個是我的 handlecommands.js 檔案
module.exports = (client) => {
client.handleCommands = async(commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}
const rest = new REST({
version: '9'
}).setToken(process.env.token);
我怎樣才能解決這個問題?(快速免責宣告,我沒有 .env 檔案,但我有一個 procfile 告訴 Heroku 該怎么做)
Worker: node index.js
uj5u.com熱心網友回復:
似乎您的 Heroku 應用程式使用的是過時/舊版本的 Node.js,其中 ??=不可用。由于您無法直接更新 Heroku 應用程式的 Node.js 版本,因此您可以在package.json.
只需在例如"description"object之后添加以下行:
"engines": {
"node": "16.x" (or another version, depending on which one you need)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/400566.html
