UNPKG

discordjs-button-helper

Version:
18 lines (13 loc) 653 B
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); }) }