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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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.
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
to do .bind({ ...interaction, client: this.client}) for example? Ok it worked but the intellisense doesn't pick it up
Azrael⛧⸸
Azrael⛧⸸OP3y ago
This is how the code looks like so far
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
I will try it and let you know the update, thank you for suggestions tho lmao you were right, right away
Azrael⛧⸸
Azrael⛧⸸OP3y ago
Azrael⛧⸸
Azrael⛧⸸OP3y ago
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
to run this.reply() instead of interaction.reply()
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Azrael⛧⸸
Azrael⛧⸸OP3y ago
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
Azrael⛧⸸
Azrael⛧⸸OP3y ago
I didn’t look at it that way Fair points I’ll scratch this then

Did you find this page helpful?