[DEV][JS]FXServer-compatible Discord.js fork

Hi everyone, recently i saw some people who wanted to use discord.js in their resources. Unfortunately, FXServer results incompatible with the package, due to a check in discord.js failing, resulting in it trying to run the browser version on node.js, subsequently crashing the entire resource.

I have forked discord.js and modified this check, here so that it will now work with FXServer’s v8 runtime.

Disclaimer:

i am not the original author of the library, i’m releasing this thanks to the license it has been distributed under, which gives me permission to redistribute the library, with the only clause being stating the changes (which i did above). I suggest you too read the license, which can be found over here in its entirety, or if you want, a nice simple tldr is also available here.

Happy Coding!

original repo: https://github.com/discordjs/discord.js

13 Likes

:slightly_smiling_face:
Thanks for it

1 Like

nice!!

1 Like

Awesome! Great to see some quality releases now and then, this most certainly is quality. Great work!

1 Like

If this works, I’ll owe you your first :beer: on your 18th Birthday! This has been what prevented me from using it for such a long time.

1 Like

guess you owe me a :beer: then :joy:
https://i.whogivesashitabout.it/d1509.png

but yeah, unfortunately lots of packages have this broken check, which is bad practice even in normal nodejs anyway… and they didnt want to accept my PR because electron declares the variable i’m checking and electron would need to run the browser version… :thinking: if you or anyone find any other broken packages, contact me, i’d give it a 90% chance that it is because of a broken browser check :smile:

I’ve had issues with request :smiley:

Checked it out, request itself doesn’t have any browser check, but it is possible that one of it’s dependencies does. An error log would help clear this up :slight_smile:

Hmm Nice can’t wait to start testing this out

An update from me:


Using the following code - from: here

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("ready", () => {
  console.log("I am ready!");
});

client.on("message", message => {
  if (message.content === "ping") {
    message.channel.send("pong");
  }
});

client.login("your token here");


Javascript: :white_check_mark: Works fine.
Typescript: :warning: Error produced.

./node_modules/discord.js/src/sharding/Shard.js
Module not found: Error: Can’t resolve ‘worker_threads’

Raw Output

This results in it trying to find the module all the way back to your root directory. My suspicion is that this is due to the following issue here.

TLDR: node and @types/node typings do not contain a definition for worker_threads. You’d have to create these typings yourself, however I am not proficient enough at Typescript to do it at this time. I’ll look into it tonight.


In other words, :partying_face: it works in regular Node V8 resources, but not when using Typescript (out of the box). This is not something @IceHax can solve.

That is really unfortunate. I am also not familiar with typescript since I’ve always used regular J’s for everything, otherwise I’d have tried to fix this. But yeah at least it works on regular node :slight_smile:

update: just pulled from upstream, enjoy an updated discord.js!

How can I install this nowadays? when I write

npm install vecchiotom/discord.js

in my terminal, it gives off a bunch of errors, that it can’t find the files. Is there a way to fix this?

I’m currently using "discord.js": "=11.6.4" in my package.json, and I’ve not had any issues with it.

1 Like

prolly either they changed it or fivem did something to their node.js implementation and that fixed it.

Yep, but it broke again for discord.js >= 12.0.0

1 Like

i might check it out later, pulling upstream might be enough to get 12.0.0 working

1 Like

definitely didnt forget about this kek, i just pulled upstream, so now it should be working again

So its on V12 now?