Discord.js v14

Hello, I’ve been attempting to deploy a Discord bot as a resource, but I’ve encountered an obstacle: the discord.js module doesn’t function as expected within the FiveM environment.
Running it separately with node index.js worked fine, with the message logged to the console.

Ubuntu version: v22.04
FXServer version: 6462 and 6683
Node.js version: v18.17.0
Discord.js version: v14.13.0

Expected and actual outcome

I expected to have Bot is ready! logged to the server console, but instead I got this error:

Reproduction steps

  1. Create a Discord bot user with Server Members and Message Contents intents enabled.
  2. Create a resource folder with the files found below. Files are index.js, fxmanifest.lua and package.json in order.
  3. Run npm install in the resource folder
  4. Add ensure dbot (example name) to the server config and start the server.
const {Client, GatewayIntentBits} = require('discord.js');
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages]});

const token = 'TOKEN_HERE'

client.on('ready', () => {
    console.log('Bot is ready!')
})

client.login(token)
fx_version 'cerulean'
game 'gta5'

author 'Gege'

server_scripts {
    'index.js'
}
{
  "name": "dbot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^14.13.0"
  }
}

This isn’t a bug, FiveM is on NodeJS v16 while DiscordJS expects NodeJS v18. If you want to use DiscordJS downgrade your package.

Discord.js specifically requires Node v16.11 or higher, so Node v18 is not expected: Installing Node.js and discord.js | discord.js Guide
Since I prefer to use discord.js v14, I won’t be downgrading it. Is there any way to update the node version that FiveM is currently running?

Sorry, I thought they upped to 18, either way FiveM is on 16.9.1, and is unlikely to get updated any time soon. There’s no way to update it without porting all that FiveM has.

Damn, such a small difference in version numbers…
From what I’ve seen, v16 was implemented in FiveM around 2 years ago, so I hope there will be an update soon. Although discord.js v13 seems to work fine, due to its differences, I think I will wait rather than remake the whole bot.

Another question came to mind. How can txAdmin use discord.js v14.11 for its bot?
I compared the package-lock.json file and it seems to be the same for the affected packages in the error I sent the screenshot of (discord.js and @discordjs/rest).

Update ?

Discord.js v13 works fine, that’s all I can tell you