Converting argument `interaction` to `this`
This sounds weird, but i have tried couple things to convert
run(interaction: ChatInputCommandInteraction)
to already making it so the class inherits run()
and then i can perform actions like this.reply()
instead of interaction.reply()
Node: v16.15.1
D.js: v14.3.035 Replies
• 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.but why
You can use
function.bind
to alter the this
contextBecause 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 Classto do
.bind({ ...interaction, client: this.client})
for example?
Ok it worked but the intellisense doesn't pick it upThis is how the code looks like so far
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I tried doing like extending my command class with BaseInteraction and then working off of that
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I dont know how to get APIInteraction data
When initializing the class within the command handling
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Im thinking about making interfaces extending baseInteraction and then i implement it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Not necessarily because the methods are there, it's just typescript doesn't recognize it on the IDE
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If i console log
this
everything is there, it's just typescript thinks something is wrongUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
so if i try
SlashCommand extends Command implements ISlashCommand
it can workUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
But
BaseInteraction
and other Classes have it defined so i just extend them and make ISlashCommand
so the methods get definedUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
I will try it and let you know the update, thank you for suggestions tho
lmao you were right, right away
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
im ded 💀
Idk what to do at this point
I've seen people do it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
to run
this.reply()
instead of interaction.reply()
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Why am i introducing a lot of problems besides this situation?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I didn’t look at it that way
Fair points
I’ll scratch this then