首页 > 解决方案 > 为什么会输出错误:“Unexpected token: '?' “在discord.js 中复制?

问题描述

我想使用 replit 来制作我的不和谐机器人。我在 node.js repli 上安装了 discord.js。我在 index.js 中插入了这段代码:

const { Client, Intents } = require("discord.js");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

client.on("ready", () => {
  console.log("If you can see this in the console when you run it on replit, I will be shocked lol")
});


client.login(process.env["BOT_TOKEN"]);

不知何故,它输出了一个错误。它指出: const token = this.client.token ?? this.client.accessToken 语法错误:意外的令牌:'?'

谢谢你,保罗10

标签: discord.js

解决方案


这是因为 repl.it 使用了不支持??操作符的旧版 Node.js。我建议遵循本教程:

https://replit.com/talk/learn/Nodejs-14-on-replit/85501


推荐阅读