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.0
35 Replies
d.js docs
d.js docs3y ago
• 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.
monbrey
monbrey3y ago
but why You can use function.bind to alter the this context
⸸⛧Stealth⛧⸸
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?
d.js docs
d.js docs3y ago
mdn 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.
⸸⛧Stealth⛧⸸
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
⸸⛧Stealth⛧⸸
to do .bind({ ...interaction, client: this.client}) for example? Ok it worked but the intellisense doesn't pick it up
⸸⛧Stealth⛧⸸
This is how the code looks like so far
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
I tried doing like extending my command class with BaseInteraction and then working off of that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
I dont know how to get APIInteraction data When initializing the class within the command handling
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
Im thinking about making interfaces extending baseInteraction and then i implement it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
Not necessarily because the methods are there, it's just typescript doesn't recognize it on the IDE
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
If i console log this everything is there, it's just typescript thinks something is wrong
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
so if i try SlashCommand extends Command implements ISlashCommand it can work
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
But BaseInteraction and other Classes have it defined so i just extend them and make ISlashCommand so the methods get defined
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
I will try it and let you know the update, thank you for suggestions tho lmao you were right, right away
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
im ded 💀 Idk what to do at this point I've seen people do it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
to run this.reply() instead of interaction.reply()
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
Why am i introducing a lot of problems besides this situation?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
⸸⛧Stealth⛧⸸
I didn’t look at it that way Fair points I’ll scratch this then
Want results from more Discord servers?
Add your server