@discordjs/core interaction create type error

Hi, I am creating a bot using @discordjs/core and it seems to be having issues with TypeScript when I do i.data.data?.name to get the name of the command, doing debugging I can see that name does exist under there but TypeScript is saying it doesn't. I could get around this by using any but my code doesn't allow any for many reasons. Is there a reason for this?
5 Replies
d.js toolkit
d.js toolkit2y ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck2y ago
this would be because the InteractioncCreate event emits for all interactions, not just command interactions similar to how in the mainlib you ought to typeguard with <Interaction>.isChatInputCommand(), you'll want to typeguard your interaction data you can import isChatInputApplicationCommandInteraction from discord-api-types/utils you'll also want to check <APIInteraction>.type
Jay
JayOP2y ago
I forgot about that part! Thanks Duck, let me try get this working then hm, using both of the things you just mentioned, typescript is still giving me the name error, is it possible for you to give me a quick snippet of what you mean incase I am missing something?
duck
duck2y ago
let interaction: APIInteraction;
if (interaction.type === InteractionType.ApplicationCommand && isChatInputApplicationCommandInteraction(interaction)) {
// do things
}
let interaction: APIInteraction;
if (interaction.type === InteractionType.ApplicationCommand && isChatInputApplicationCommandInteraction(interaction)) {
// do things
}
Jay
JayOP2y ago
there we go! thank you so much!
Want results from more Discord servers?
Add your server