listener not loading.

I have no idea what the issue is, but the listener just never loads.
import { Listener } from '@sapphire/framework';

export class presenceUpdate extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options){
super(context, {
...options,

});
this.container.logger.info("User presence update listener loaded")
}
public run(){
fetch(`http://roundhouse.proxy.rlwy.net:59002/incrementMessageCounter`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

this.container.logger.info("User presence updated")
}
}
import { Listener } from '@sapphire/framework';

export class presenceUpdate extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options){
super(context, {
...options,

});
this.container.logger.info("User presence update listener loaded")
}
public run(){
fetch(`http://roundhouse.proxy.rlwy.net:59002/incrementMessageCounter`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

this.container.logger.info("User presence updated")
}
}
according to the doc's it's supposed to auto load the listener?
No description
Solution:
i've got it, i used virtual pieces rather than the default file system. i assume it has something to do with the nx setup, etc.
Jump to solution
8 Replies
Spinel
Spinel6mo ago
1. Which version of @sapphire/framework are you using? 2. What's your file/folder structure? 3. Did you use the CLI to generate your bot? 4. What's your main (CJS) or module (ESM) property in package.json 5. Are you using TypeScript? And if so, how are you compiling and running your code? That is to say, what are your build and startup scripts? - Did you remove your output folder and rebuild then try again? 6. Is your problem related to message commands? Did you add loadMessageCommandListeners to your SapphireClient options Remember that if you are new to @sapphire/framework it is important that you read the user guide.
Favna
Favna6mo ago
4 and 5
Favna
Favna6mo ago
also you need to enable the privileged intent: https://discordjs.guide/popular-topics/intents.html#privileged-intents
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Favna
Favna6mo ago
which includes checking it here on https://discord.dev, and it's also important to note that just like Message Content intent you will need to apply to get access and have a good reason for needing that access ocne your bot is close to 100 servers
No description
Jaymart
JaymartOP6mo ago
intents are enabled. Im using TS and im using nx to run it so, pnpm nx serve discord and no messages. presence update listener this is my package.json
{
"name": "@vanityroles-ecosystem/source",
"version": "0.0.0",
"license": "MIT",
"scripts": {},
"private": true,
"type": "module",
"prettier": "@sapphire/prettier-config",
"devDependencies": {
"@nx/esbuild": "19.2.0",
"@nx/eslint": "19.2.0",
"@nx/eslint-plugin": "19.2.0",
"@nx/js": "19.2.0",
"@nx/node": "^19.2.0",
"@nx/workspace": "19.2.0",
"@swc-node/register": "~1.9.1",
"@swc/core": "~1.5.7",
"@swc/helpers": "~0.5.11",
"@types/node": "~18.16.20",
"@typescript-eslint/eslint-plugin": "^7.3.0",
"@typescript-eslint/parser": "^7.3.0",
"esbuild": "^0.19.2",
"eslint": "~8.57.0",
"eslint-config-prettier": "^9.0.0",
"nx": "19.2.0",
"prettier": "^2.6.2",
"typescript": "~5.4.5"
},
"dependencies": {
"@influxdata/influxdb-client": "^1.33.2",
"@kaname-png/plugin-influxdb": "^1.4.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.46.1",
"@opentelemetry/sdk-node": "^0.52.0",
"@sapphire/decorators": "^6.1.0",
"@sapphire/discord.js-utilities": "^7.3.0",
"@sapphire/eslint-config": "^5.0.5",
"@sapphire/framework": "^5.2.1",
"@sapphire/lexure": "^1.1.7",
"@sapphire/pieces": "^4.2.2",
"@sapphire/plugin-api": "^6.1.1",
"@sapphire/plugin-logger": "^4.0.2",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ratelimits": "^2.4.9",
"@sapphire/snowflake": "^3.5.3",
"@sapphire/ts-config": "^5.0.1",
"@sapphire/utilities": "^3.16.2",
"@sentry/node": "^8.7.0",
"@types/express": "^4.17.21",
"discord-cross-hosting": "^2.3.8",
"discord-hybrid-sharding": "^2.2.0",
"discord.js": "14.15.3",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"prom-client": "^15.1.2",
"redis": "^4.6.14",
"ts-node": "^10.9.2",
"tslib": "^2.3.0",
"zod": "^3.23.8"
}
}
{
"name": "@vanityroles-ecosystem/source",
"version": "0.0.0",
"license": "MIT",
"scripts": {},
"private": true,
"type": "module",
"prettier": "@sapphire/prettier-config",
"devDependencies": {
"@nx/esbuild": "19.2.0",
"@nx/eslint": "19.2.0",
"@nx/eslint-plugin": "19.2.0",
"@nx/js": "19.2.0",
"@nx/node": "^19.2.0",
"@nx/workspace": "19.2.0",
"@swc-node/register": "~1.9.1",
"@swc/core": "~1.5.7",
"@swc/helpers": "~0.5.11",
"@types/node": "~18.16.20",
"@typescript-eslint/eslint-plugin": "^7.3.0",
"@typescript-eslint/parser": "^7.3.0",
"esbuild": "^0.19.2",
"eslint": "~8.57.0",
"eslint-config-prettier": "^9.0.0",
"nx": "19.2.0",
"prettier": "^2.6.2",
"typescript": "~5.4.5"
},
"dependencies": {
"@influxdata/influxdb-client": "^1.33.2",
"@kaname-png/plugin-influxdb": "^1.4.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.46.1",
"@opentelemetry/sdk-node": "^0.52.0",
"@sapphire/decorators": "^6.1.0",
"@sapphire/discord.js-utilities": "^7.3.0",
"@sapphire/eslint-config": "^5.0.5",
"@sapphire/framework": "^5.2.1",
"@sapphire/lexure": "^1.1.7",
"@sapphire/pieces": "^4.2.2",
"@sapphire/plugin-api": "^6.1.1",
"@sapphire/plugin-logger": "^4.0.2",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ratelimits": "^2.4.9",
"@sapphire/snowflake": "^3.5.3",
"@sapphire/ts-config": "^5.0.1",
"@sapphire/utilities": "^3.16.2",
"@sentry/node": "^8.7.0",
"@types/express": "^4.17.21",
"discord-cross-hosting": "^2.3.8",
"discord-hybrid-sharding": "^2.2.0",
"discord.js": "14.15.3",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"prom-client": "^15.1.2",
"redis": "^4.6.14",
"ts-node": "^10.9.2",
"tslib": "^2.3.0",
"zod": "^3.23.8"
}
}
and my project.json from nx which has the build and such in it.
{
"name": "discord",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/discord/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "dist/apps/discord",
"format": ["esm"],
"bundle": true,
"main": "apps/discord/src/index.ts",
"tsConfig": "apps/discord/tsconfig.app.json",
"assets": ["apps/discord/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "discord:build"
},
"configurations": {
"development": {
"buildTarget": "discord:build:development"
},
"production": {
"buildTarget": "discord:build:production"
}
}
}
}
}
{
"name": "discord",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/discord/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "dist/apps/discord",
"format": ["esm"],
"bundle": true,
"main": "apps/discord/src/index.ts",
"tsConfig": "apps/discord/tsconfig.app.json",
"assets": ["apps/discord/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "discord:build"
},
"configurations": {
"development": {
"buildTarget": "discord:build:development"
},
"production": {
"buildTarget": "discord:build:production"
}
}
}
}
}
Favna
Favna6mo ago
looks like your problem is related to not setting a main property, see the big red block at the very start of the guide: https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire How this is going to have to be implemented for you when using nx is for you to figure out though. I have no experience with nx but I would expect that every subpackage has its own package.json as is the case of any monorepo setup and so you would put it in the appropiate subpackage package.json and pray that nx sets process.cwd() correctly I guess
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
Solution
Jaymart
Jaymart6mo ago
i've got it, i used virtual pieces rather than the default file system. i assume it has something to do with the nx setup, etc.
Jaymart
JaymartOP6mo ago
also put a _load.ts in the listeners folder
Want results from more Discord servers?
Add your server