node.js - SyntaxError:Discord.js v12 中的令牌无效或意外
问题描述
我已经在 Discord.js 中启动了一个新机器人,当我尝试运行我的 index.js 文件时,SyntaxError: Invalid or unexpected token
会发生该错误。我的 index.js 文件如下图...(代码太多,我只好缩短了)
const fs = require("fs");
const Discord = require('discord.js');
const { prefix, token } = require("./config.json");
const modules = fs.readdirSync("./commands")
client.commands = new Discord.Collection()
for(const cmds of modules) {
const command = require(`./commands/${cmds}`)
client.commands.set(command.name, command);
}
client.on('ready', () => {
// Status Code Block
}
});
client.on('message', async message => {
const args = message.content.slice(prefix.length).split(/ +/g)
const cmdName = args.shift()
if(!client.commands.has(cmdName)) return
const command = client.commands.get(cmdName)
command.run(message, args, client)
})
client.login(token);
不知道有什么问题。有人可以帮忙吗?
解决方案
我在您的代码中缺少的是客户端定义。
const client = new Discord.Client();
但是让我们假设您在索引文件中定义了一个客户端。您是否尝试过在您的不和谐开发者门户上重新生成令牌?也许它以某种方式泄露并被撤销。
推荐阅读
- html - 当项目数未填满页面时的css网格最大宽度
- apache-spark - Spark Executors getting Terminated
- python - How would i fix this error in python WTForms?
- sql - 正则表达式 - 仅在 xxx 的第二个位置包含 0
- php - Envoy 并通过 ssh 连接用户名和大写字母
- azure - Azure 数据工厂数据流任务不能以 prem 作为源
- python - Function declaring global variable doesn't work in debug mode
- python - python相当于curl命令,具有api令牌基本身份验证
- pseudocode - 必须逐行读取伪代码并解析输入的行
- php - $_SERVER 中的 PATH_INFO 始终为空 - NGINX + FPM 7.3 + Ubuntu 18.04