[英]Discord.js module error before first line of code
I just started writing a Discord bot in Visual Studio Code in Javascript, it's literally the most basic it can be, loading discord.js, on ready event and then login.我刚开始在 Javascript 的 Visual Studio Code 中编写 Discord 机器人,它实际上是最基本的,加载 discord.js,在就绪事件上然后登录。
Before it even runs the first line of code, I get this error:在它运行第一行代码之前,我得到了这个错误:
Debugger listening on ws://127.0.0.1:5489/3cf4a3d1-ef26-4c1c-a274-030564d40731
For help see https://nodejs.org/en/docs/inspector
i:\Coding\Bots\PURGE\node_modules\discord.js\src\util\Util.js:584
str = str.replace(/@([^<>@ ]*)/gmsu, (match, target) => {
^
SyntaxError: Invalid regular expression flags
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (i:\Coding\Bots\PURGE\node_modules\discord.js\src\index.js:3:14)
Process exited with code 1
The error occurs in the Discord.js module which I didn't write , and have no idea how it works and therefore cannot fix.该错误发生在我没有编写的 Discord.js 模块中,并且不知道它是如何工作的,因此无法修复。
Re-installling Discord.js didn't help, reinstalling Visual Studio Code didn't either.重新安装 Discord.js 没有帮助,重新安装 Visual Studio Code 也没有帮助。 I sent a friend the exact same files (even the same node_modules folder) and when he runs it, it works with no problems.我向朋友发送了完全相同的文件(甚至是相同的 node_modules 文件夹),当他运行它时,它可以正常工作。 Any ideas what the problem is or how I can fix it?任何想法是什么问题或我该如何解决?
This is my code:这是我的代码:
console.log("test") //DOESNT LOG
const Discord = require("discord.js");
const fs = require("fs");
const config = require("./config.json");
let christian = {}
//This will define our bot
var bot = new Discord.Client()
bot.on('message', async msg => {
console.log(msg)
})
bot.on('ready', () => {
console.log(`-----Purge#2420 Online-----\nWatching over ${bot.guilds.cache.size} servers |`)
});
bot.login(config.token)
From the comments:从评论:
I am on [Node] v8.9.4, [...] on Discord.js V12我在 [Node] v8.9.4,[...] 在 Discord.js V12
From Discord JS' upgrade guide: :来自Discord JS 的升级指南:
v12 requires Node 12.x or higher to use, so make sure you're up-to-date. v12 需要使用 Node 12.x 或更高版本,因此请确保您是最新的。
That is -- you'll have to upgrade your Node.js.也就是说——你必须升级你的 Node.js。
In the ready
event you have an invalid string which maybe causing the error '-----Purge#2420 Online-----\nWatching over ${bot.guilds.cache.size} servers |
在ready
事件中,您有一个无效字符串,这可能会导致错误'-----Purge#2420 Online-----\nWatching over ${bot.guilds.cache.size} servers |
it maybe crashing due to the invalid single quote '
at string's start, try replacing it with a backtick (`).它可能由于字符串开头的无效单引号'
而崩溃,请尝试用反引号 (`) 替换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.