ColorResolvable being quirky
Hi yall I want to set e color for my embed, so I gave it a string in the format of
"#abcxyz" and it said "me no like that". Then I checked the reference and that should have worked. Then I tried an array of three number with rgb format and then it said again "me no like that". What does it take? And why does the reference give an array of numbers as example, yet number[] is not in the union type?20 Replies
could you share your code, error, and discord.js version
oh sorry
14.22.1
Error
I would start by updating your version to latest
also could you log
avgColor.value?.slice(0, 2)
an example value
ok I think I figured it out it is just a typing issue/bug
this works
but this does not
is avgColor a custom object you created?
hmmm
I think that is the culprit then
but then its weird that the documentation says it does
I did not have any issue us the string
hmm
JS does not care about type semantics ts does tho
but TS does
yeah
I think its because there is only a conversion from string to ColorResolvable of the string starts with a # and contains onlu 6 symbols
you could do a
// @ts-expect-error before setcolor
but my recomendations is to add a fuctions that returns the type [red: number, green: number, blue: number] or other resolvableill have to make a conversion since the function is from a library
but sure
thanks
!solved
I think you will find this useful maybe it will return the number for a color from ColorResolvable.
not sure it solves the underling issue tho
question how can a number a color? isnt a color a point in R^3
aka a three dimensional number?
0xffffff is equal to 16,777,215 there for #FFFFFF or [255,255,255] is also equal to 16,777,215
Discord API takes a number as input the builder just abstracts it for youokay but thats still three numbers
In an abstract sense, sure. But it's been collapsed down into a single number
Also another solution is to type guard function
I prefer
const color = […] satisfies ColorResolvable