How does one create a ButtonBuilder that does not accept Links or Premium buttons?

I am creating an interaction handler that requires buttons with custom_ids (as such Premium and Link buttons are out the door). How can i force them to be buttons without those styles at compile-time?
2 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Thorminate
ThorminateOP5mo ago
This handler i referred to takes in a ButtonBuilder and a Callback, if the button does not have a customId (like you said) there is nothing to callback and then its not necessary for the handler to be in place at all. Here is an example for it if you so desire it:
export default new Interaction({
data: new ButtonBuilder()
.setCustomId("deletePlayer")
.setLabel("Delete")
.setStyle(ButtonStyle.Danger),

interactionType: "button",
acknowledge: false,
passPlayer: false,
environmentOnly: false,
passEnvironment: false,

callback: async ({ context }) => {
if (!(await Player.find(context.user.id))) {
await context.update({
content: "You don't exist in the DB, therefore you cannot be deleted.",
});
return;
}

await context.update({
content: "Are you sure you want to delete your persona?",
components: componentWrapper(deletePlayerConfirmed.data),
});
},

onError(e) {
log({
header: "Button Error",
processName: "DeletePlayerButton",
payload: e,
type: "Error",
});
},
});
export default new Interaction({
data: new ButtonBuilder()
.setCustomId("deletePlayer")
.setLabel("Delete")
.setStyle(ButtonStyle.Danger),

interactionType: "button",
acknowledge: false,
passPlayer: false,
environmentOnly: false,
passEnvironment: false,

callback: async ({ context }) => {
if (!(await Player.find(context.user.id))) {
await context.update({
content: "You don't exist in the DB, therefore you cannot be deleted.",
});
return;
}

await context.update({
content: "Are you sure you want to delete your persona?",
components: componentWrapper(deletePlayerConfirmed.data),
});
},

onError(e) {
log({
header: "Button Error",
processName: "DeletePlayerButton",
payload: e,
type: "Error",
});
},
});
The reasoning for this is mostly because I'm lazy and don't want to type assert data to APIButtonComponentWithCustomId all the time

Did you find this page helpful?