#Converting argument `interaction` to `this`
53 messages · Page 1 of 1 (latest)
• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
Because it seems that it would be faster to access options and etc
What do you mean by function.bind
Any code example by any chance?
or like links to?
Function.prototype.bind()
The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
I did as followed, but now inside the command class typescript shows this when accessing properties of this but it console logs a different Class
to do .bind({ ...interaction, client: this.client}) for example?
Ok it worked but the intellisense doesn't pick it up
This is how the code looks like so far
Typescript hates this kind of things, messing with bind and prototype directly is not smtg that will make typescript happy.
I would highly recommend following othet approach or if you rly want to do it like this use some type casting or change your types completly, and you will have to narrow down the types to make sure you have what you want.
I would strongly recommend following another approach
I tried doing like extending my command class with BaseInteraction and then working off of that
And what was the issue?
I dont know how to get APIInteraction data
When initializing the class within the command handling
Does djs even expose the raw api data to the user?
I do not know, i even tried going through the source code of djs to maybe reverse engineer it and somehow do it, but it doesn't work
I dont remember raw api data being exposed to the user
If you want to create a class based of another one there are ways of doing it that do not include bind but they are a little messy to setup properly in a way that you get intellisense
Im thinking about making interfaces extending baseInteraction and then i implement it
Implementing it wont solve the issue because it means you need to implement the methods yourself
Not necessarily because the methods are there, it's just typescript doesn't recognize it on the IDE
Exactly
If i console log this everything is there, it's just typescript thinks something is wrong
An interface is a ts thing
If it doesnt recognize they are there it will ask you to define them or else it wont compile
But BaseInteraction and other Classes have it defined so i just extend them and make ISlashCommand so the methods get defined
You can try but im pretty sure it wont compile and will scream at you
Again, using bind is not smtg that should be done
I will try it and let you know the update, thank you for suggestions tho
lmao you were right, right away

First, why do you want to merge the interaction methods on your command class?
Thats just a memory hog and not efficient at all, + is way less mantainable and a pain to read
to run this.reply() instead of interaction.reply()
How can that be better?
You are introducing a lot of problems to deal with just for no reason
Why am i introducing a lot of problems besides this situation?
First, if you have 2 methods with the same name one will be deleted.
Second, you are adding more processing to do on every command call
Third, linked with the second, you are consuming more memory doing this for no apparent reason
Fourth, is just against best practices
There is more to it but i cant be bothered to go through everything. Just read about bind problems and you will understand
But its your code, if you rly want to do it there are ways if doing it and having intellisense