message listeners stopped working in sapphire v4 on my bot

hi, this is my listener code:
const { Events, Listener, container } = require('@sapphire/framework');

module.exports = class MessageCreateListener extends Listener {
constructor(context, options) {
super(context, { ...options, event: 'messageCreate' });
}

onLoad() {
container.logger.info('MessageCreateListener has been loaded.')
}

async run(message) {
if (message.channel.type !== 'DM') return;
// do the modmail related processing
}
};
const { Events, Listener, container } = require('@sapphire/framework');

module.exports = class MessageCreateListener extends Listener {
constructor(context, options) {
super(context, { ...options, event: 'messageCreate' });
}

onLoad() {
container.logger.info('MessageCreateListener has been loaded.')
}

async run(message) {
if (message.channel.type !== 'DM') return;
// do the modmail related processing
}
};
file structure is also same: zeno/src/listeners/messageCreate.js below messageCommandFinish listener/event code also stopped working:
const { Events, Listener, container } = require('@sapphire/framework');
const { OWNER_IDS } = process.env;

module.exports = class CommandFinishedListener extends Listener {
constructor(context, options) {
super(context, {
...options,
event: Events.MessageCommandFinish
});
}

async run(message, command) {
// do log processing, upload to grafana etc.
}
};
const { Events, Listener, container } = require('@sapphire/framework');
const { OWNER_IDS } = process.env;

module.exports = class CommandFinishedListener extends Listener {
constructor(context, options) {
super(context, {
...options,
event: Events.MessageCommandFinish
});
}

async run(message, command) {
// do log processing, upload to grafana etc.
}
};
i dont see any breaking changes regarding listeners/events in sapphire migrating guide and this same code was working perfectly fine but stopped working after upgrading to sapphire v4 and I didnt need to make any changes to this code for migration. Is there anything I missed or doing wrong? pls lemme know if i need to provide any other info which i might have missed. if anyone can point me in right direction, I would be immensely thankful. 🙏🏽
Solution:
Okay Vladdy found the problem @owoer You forgot to call super.onLoad() in your onLoad method ```js onLoad() {...
Jump to solution
19 Replies
Favna
Favna2y ago
For starters why not use Events.MessageCreate Anyway also remember the djs v14 migration. Not sure if they changed message stuff. Slash commands are the future mate.
owoer
owoer2y ago
ok I used the enum now, the strange thing is the listeners loads just fine on bot startup but the logic in run method does not fire
Favna
Favna2y ago
can you make a github repository with minimal code that has the bug reproduced? I'll need to dig deeper with debugging.
owoer
owoer2y ago
ok sure, thanks for helping ^^ one weird thing i observed is that i use coc-tsserver for intellisense and it shows autocompletion for onLoad but doesnt show any tab completion for run method
owoer
owoer2y ago
Favna
Favna2y ago
a neovim user that uses raw JS instead of TS. Now there is a combination that's new to me. anyway https://github.com/sapphiredev/framework/blob/main/src/optional-listeners/message-command-listeners/CoreMessageCreate.ts works just fine and that also has run
owoer
owoer2y ago
😨 sorry about that, im still learning i'll setup the minimal repro and come back when done, thank you for your time ^^
Favna
Favna2y ago
I mean I envy anyone who can really use vim. I only sometimes enable vscode-vim and even then I don't feel entirely comfortable.
owoer
owoer2y ago
fair enough :P ok i made a minimal repro here : https://github.com/o-wo/sapphire-v4-messageCreate-event-minimal-repro I have tested on separate test bot with required intents enabled on dashboard and it gives same results, the code is kinda ugly (sorry about that, still noob and learning js from free time after school) >.<
Favna
Favna2y ago
Ok i'm looking into this now
Solution
Favna
Favna2y ago
Okay Vladdy found the problem @owoer You forgot to call super.onLoad() in your onLoad method
onLoad() {
super.onLoad();
container.logger.info('MessageCommandFinish event listener is now loaded.');
}
onLoad() {
super.onLoad();
container.logger.info('MessageCommandFinish event listener is now loaded.');
}
owoer
owoer2y ago
oh interesting, it works after adding that, thank you is it a breaking change in sapphire V4? since on sapphire 3.x i never had to call that super function and listeners worked fine.
vladdy
vladdy2y ago
No, that code has been unchanged since probs sapphire v2 I seriously doubt it worked for you before that too
owoer
owoer2y ago
it really did xd
vladdy
vladdy2y ago
and they probably worked because you never overrode onLoad onLoad handles the actual registering of the listener on the emitter
Want results from more Discord servers?
Add your server