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
- Create a Discord bot user with Server Members and Message Contents intents enabled.
- Create a resource folder with the files found below. Files are
index.js
,fxmanifest.lua
andpackage.json
in order. - Run
npm install
in the resource folder - 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"
}
}