interactionCreate listener

import { Listener } from '@sapphire/framework';

export class UserEvent extends Listener {
constructor(context, options = {}) {
super(context, {
...options,
event: 'interactionCreate',
once: false
});
}

async run(interaction) {
if (interaction.isButton()) {
if (interaction.customId === "btn_reg") {

}
}
}
}
import { Listener } from '@sapphire/framework';

export class UserEvent extends Listener {
constructor(context, options = {}) {
super(context, {
...options,
event: 'interactionCreate',
once: false
});
}

async run(interaction) {
if (interaction.isButton()) {
if (interaction.customId === "btn_reg") {

}
}
}
}
i just tried to use the listener, but there is an error when trying to press the button that I gave a custom id, am I doing something that has been changed in the latest version?
8 Replies
alqm
alqm2w ago
you shouldnt be using listeners to handle a button
alqm
alqm2w ago
Sapphire Framework
Buttons | Sapphire
Buttons are components that are clickable. You will recieve an interaction for every click of a button! Here's an
alqm
alqm2w ago
also would probably be helpful if you provided us the error
čamdžić
čamdžić2w ago
I think that event is not even registered (I’m not sure) In constructor you did options = {} And yeah, use interaction handlers
el
elOP2w ago
is the interactionHandler only for 1 command? or can create multiple commands, but how? is there an example?
alqm
alqm2w ago
there is no need to handle commands via an interaction handler. sapphire does it automatically unless you modified your registries settings the link i provided shows you how to handle a button properly
el
elOP2w ago
thank, i'll try it
mallusrgreat
mallusrgreat2w ago
you have to reply to the interaction for the error to not appear

Did you find this page helpful?