#How to handle tons of Buttons

1 messages · Page 1 of 1 (latest)

gleaming fox

Hi. I wanted to ask your advice for my code.

I have a bot, in committee, that has a lot of buttons. I structure the bot's folder like this: src/events/{category}/{interaction-customId}, which means that I if I have 100 buttons, I will have 100 files to have as neat a structure as possible, making it easy to maintain.

The problem is that with my current eventHandler, I create as many 100 client.on(interactionCreate,...), exposing myself to lots of memory leaks, anceh because I have to put .setMaxListeners(0) to the discord.js emitter.

My question is, how do I handle all these events without doing 100 client.on? The short solution is with a switch(customId), but I don't think it is neat and professional, because a switch should not be used to call "only" the function and do nothing else.

PS: 100 is a number to exaggerate, but it gives the idea.