#reusable components

26 messages · Page 1 of 1 (latest)

viral spoke

what would be the best way to implement reusable components inside my discord bot? currently, every one of my responses to commands are containers, and even just a simple container with an accent color and text display requires alot of boilerplate. im thinking of maybe creating functions that are like reusable where its a container with a text display and i just pass it an accent color and text content but im not sure if this the best way. should i be using functions, class methods or something else? not really sure.

wet shuttleBOT
keen willow

"best" is really subjective tbh, to oop or to not oop is also a big debate

from my personal opinion, oop but without static methods, those can be individual functions

can include them in their own object to simulate a namespace

viral spoke

youre talking about a class that would have methods that would just be functions?

keen willow

but you're pretty much free to what you want, as long as you're consistent with your rules

viral spoke

alright alright

keen willow
viral spoke

ty for the info

crystal agate
viral spoke

i took a look and it looks pretty nice. but i feel like its too much when it comes to responses since those deal with components more

like for example my concept is ill have a bunch of wrappers that are just functions

so ill have a function that takes in content and an optional colorresolvable that just returns a container with said content and color

and i can have a makeEphemeral function wrap around it if it needs to be ephemeral

id probably use similar implementation like you when it comes to full on buttons/modals/menus etc

crystal agate

Hmm. Ofc. It should always depend on what gives you the best DX while doing the best job

finding that middle ground takes a lot of trial and error

crystal agate

if the stuff you're doing with said components is simple, like just adding text or changing the color etc, it would make sense to make do with something simple as well.

viral spoke

i was just talking about like

makeEphemeral(createSimpleResponse('example components v2', 'Red')

but now that you mention it, i could havve a decorator like

@Ephemeral over anything i want ephemeral

ill need to learn how to make them since ive never used or made one before lol

crystal agate

@ is just syntactic sugar languages use