Can't create new listener

I've tried to create a ready listener as the getting started shows, but it crashes
Solution:
exact same error as #TypeError Class constructor _SapphireClient cannot be invoked without 'new' This means your target wasn't set so it defaults to ES3 which is ancient JS that isn't supported and doesn't supported classes...
Jump to solution
3 Replies
ikoli
ikoliOP15mo ago
Error when loading 'C:\Users\Peter\Desktop\game\src\listeners\ready.ts': TypeError: Class constructor _Listener cannot be invoked without 'new'
at new ReadyListener (C:\Users\Peter\Desktop\game\src\listeners\ready.ts:23:42)
at _ListenerStore.construct (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:325:10)
at _ListenerStore.loadPath (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:354:17)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at _ListenerStore.loadAll (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:245:21)
at async Promise.all (index 3)
at _SapphireClient.login (C:\Users\Peter\Desktop\game\node_modules\@sapphire\framework\src\lib\SapphireClient.ts:352:3)
Error when loading 'C:\Users\Peter\Desktop\game\src\listeners\ready.ts': TypeError: Class constructor _Listener cannot be invoked without 'new'
at new ReadyListener (C:\Users\Peter\Desktop\game\src\listeners\ready.ts:23:42)
at _ListenerStore.construct (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:325:10)
at _ListenerStore.loadPath (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:354:17)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at _ListenerStore.loadAll (C:\Users\Peter\Desktop\game\node_modules\@sapphire\pieces\src\lib\structures\Store.ts:245:21)
at async Promise.all (index 3)
at _SapphireClient.login (C:\Users\Peter\Desktop\game\node_modules\@sapphire\framework\src\lib\SapphireClient.ts:352:3)
"dependencies": {
"@sapphire/framework": "^4.8.2",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
}
"dependencies": {
"@sapphire/framework": "^4.8.2",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
}
import { Listener } from '@sapphire/framework';
import type { Client } from 'discord.js';

export class ReadyListener extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
once: true,
event: 'ready'
});
}
public run(client: Client) {
const { username, id } = client.user!;
this.container.logger.info(`Successfully logged in as ${username} (${id})`);
}
}
import { Listener } from '@sapphire/framework';
import type { Client } from 'discord.js';

export class ReadyListener extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
once: true,
event: 'ready'
});
}
public run(client: Client) {
const { username, id } = client.user!;
this.container.logger.info(`Successfully logged in as ${username} (${id})`);
}
}
Solution
Favna
Favna15mo ago
exact same error as #TypeError Class constructor _SapphireClient cannot be invoked without 'new' This means your target wasn't set so it defaults to ES3 which is ancient JS that isn't supported and doesn't supported classes
ikoli
ikoliOP15mo ago
Yep found at the moment! Thanks

Did you find this page helpful?