discordjs-button-helper
Version:
A easy way to use buttons in discord.js
18 lines (13 loc) • 653 B
text/typescript
import { ButtonInteraction, MessageComponentInteraction, TextChannel } from 'discord.js';
export function onButtonClick(customId: string, channel: TextChannel, maxClicks: number, click: (i: ButtonInteraction) => void, customFilter?: (i: MessageComponentInteraction) => boolean) {
let filter = (i: MessageComponentInteraction) => { return i.customId === customId };
if (customFilter) filter = customFilter;
const collector = channel.createMessageComponentCollector({
filter,
max: maxClicks
});
collector.on('collect', (i) => {
if (!i.isButton()) return;
click(i);
})
}