Aci
Aci

Reputation: 566

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.

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.

Re-installling Discord.js didn't help, reinstalling Visual Studio Code didn't either. I sent a friend the exact same files (even the same node_modules folder) and when he runs it, it works with no problems. 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)

Upvotes: 0

Views: 373

Answers (2)

AKX
AKX

Reputation: 169416

From the comments:

I am on [Node] v8.9.4, [...] on Discord.js V12

From Discord JS' upgrade guide::

v12 requires Node 12.x or higher to use, so make sure you're up-to-date.

That is -- you'll have to upgrade your Node.js.

Upvotes: 2

Angel
Angel

Reputation: 114

In the ready event you have an invalid string which maybe causing the error '-----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 (`).

Read more about template strings here

Upvotes: 0

Related Questions