NamVr / DiscordBot-Template

A boilerplate / template for discord.js v14 bots with 100% coverage of Discord API, command handler, error handler based on https://discordjs.guide/
https://djs.docs.namanvrati.me/
Apache License 2.0
322 stars 75 forks source link

Add customid to the button handler #28

Closed thecookieswhoplays closed 1 year ago

thecookieswhoplays commented 1 year ago

What it does is that you can add args by adding them like this. commandname-[arg1]-[arg2] you can then access them from the interaction.args.arg1 like this

GoudronViande24 commented 1 year ago

@NamVr check this out, the guys asked for my opinion on Discord but you are more up to date on this project than me.

NamVr commented 1 year ago

I don't understand the purpose, what does it do exactly?

thecookieswhoplays commented 1 year ago

let's say I want a button which send a msg to a user. You could make the id sendmsg-[userid] and then on the button handler create a file sendmsg-[id] you can then access id with interaction.args.id to then send the message to him.

NamVr commented 1 year ago

I still don't get it, why need so much changes when you can just pass properties via the button function.

GoudronViande24 commented 1 year ago

Most other good templates and framework offer this option. Let's say you want to make a button through this handler, but you must store custom data with it. This is (mostly) the only way.

GoudronViande24 commented 1 year ago

It's also a non-breaking change that add an option, why not!

NamVr commented 1 year ago

Can't you just de-structure the customId from button handler directly? "sample-12345" just get "12345", why need changes in core template?

It's also a non-breaking change that add an option, why not!

The code seems to be poorly written and I don't see any actual purpose of this feature here. It makes no sense to pass extra data with buttons because of customId, you know you're using THAT customId for THAT purpose. Correct me if I'm wrong.

GoudronViande24 commented 1 year ago

How would the handler know which js function to execute on receiving sample-12345? You don't know in advance what the id will be.

NamVr commented 1 year ago

The handler doesn't have to know about this as this a custom functionality. To be noted this template needs to be fairly basic and simple for all users by keeping just enough features for it to function properly and good. It is really possible to add hundreds of such custom features into the template but again it ruins the simplicity of the template, it is also meant to be beginner friendly. We don't want to create custom functionality that might conflict with functionality a user would try to make, many people customize button handler to their liking and this could potentially cause conflicts for the same.

NamVr commented 1 year ago

By this I have an idea to add wildcard entries as customId functionality, that would be very good and will support all custom features as mentioned in this PR.

NamVr commented 1 year ago

https://github.com/NamVr/DiscordBot-Template/blob/master/events/buttonInteraction.js#L27

You can modify this statement right at line 27 as mentioned to include a regex test instead of normal checking. Then in "id" section of a button handler, you can create the regex and buttonInteraction.js will test that regex and handle it appropriately.

GoudronViande24 commented 1 year ago

By this I have an idea to add wildcard entries as customId functionality, that would be very good and will support all custom features as mentioned in this PR.

It's pretty much what this is...

NamVr commented 1 year ago

Correct, I dropped correct hints here to get started. Thank you for leaving the PR for the idea!