所以我一直得到这个特定的错误,无论我尝试什么,每次错误都是一样的,我显示我的索引文件的唯一原因是因为它开始时,我更新了索引采取不和谐的斜线命令,node.js的索引文件是一个文件没有访问,我使用replit所有这一切,所以除非我会显示隐藏的文件,我没有直接访问该文件。
错误:
/home/runner/blah-blah/node_modules/@discordjs/rest/dist/index.js:64
var DefaultUserAgentAppendix = import_node_process.default.release?.name === "node" ? Node.js/${import_node_process.default.version} : "";
^
SyntaxError: Unexpected token '.'
这里是我的索引文件:
const express = require('express');
const { Client, Collection, Intents } = require('discord.js');
const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
require('dotenv').config();
const app = express();
app.get('/', (req, res) => {
res.send('Hello Express app!');
});
app.listen(3000, () => {
console.log('Server started');
});
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
const rest = new REST({ version: '9' }).setToken(process.env.token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(process.env.clientId),
{ body: client.commands.map(command => command.data.toJSON()) }
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
client.once('ready', () => {
console.log('Bot is online');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'An error occurred while executing this command.', ephemeral: true });
}
});
const nodeProcess = require('process');
const releaseName = nodeProcess.release ? nodeProcess.release.name : null;
const nodeVersion = nodeProcess.version;
const DefaultUserAgentAppendix = releaseName && releaseName === 'node' ? `Node.js/${nodeVersion}` : '';
// Manually set the user agent
rest.userAgent = `DiscordBot (${process.env.clientId}, ${client.user.username}) ${DefaultUserAgentAppendix}`;
client.login(process.env.token).catch(() => {
console.log('Invalid token');
});
这是我的package.json
{
"name": "Bucket-Giveaways-Bot",
"version": "1.3.0",
"description": "A simple discord giveaway bot",
"main": "index.js",
"dependencies": {
"@discordjs/builders": "^1.6.3",
"@discordjs/rest": "^1.7.1",
"discord-api-types": "^0.37.42",
"discord-giveaways": "^4.5.1",
"discord.js": "^12.5.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"ms": "^2.1.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Bucket",
"license": "ISC"
}
我从来没有真正使用过node.js,我通常用python制作我的机器人,但我想挑战自己,我尝试使用chat gpt,主要是bc我没有任何编码器朋友,甚至chat gpt也无法修复它。
1条答案
按热度按时间wsewodh21#
这似乎是您使用的节点版本的问题。
?
运算符不被您使用的节点版本所理解。您可以使用n
更新节点,例如npx n -latest
。