Property 'getMessage' does not exist

Hello, I've just updated to the latest version of discord.js and I can't seem to access the getMessage option in interaction.options. is there a type checking needed that I'm not aware of?
async exec(interaction: ContextMenuCommandInteraction<CacheType>) {
const { music } = this.bot.managers;
const user = interaction.user;
const message = interaction.options.getMessage('message', true); <--- ERR
let query = message.content;
let textChannel = interaction.channel;
async exec(interaction: ContextMenuCommandInteraction<CacheType>) {
const { music } = this.bot.managers;
const user = interaction.user;
const message = interaction.options.getMessage('message', true); <--- ERR
let query = message.content;
let textChannel = interaction.channel;
I get this error with the code above:
Property 'getMessage' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getUser" | "getMember" | ... 7 more ... | "getSubcommand">'.ts(2339)
Property 'getMessage' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getUser" | "getMember" | ... 7 more ... | "getSubcommand">'.ts(2339)
package.json "typescript": "^5.4.2" "discord.js": "^14.15.2" Thanks in adv!
4 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
TÆMBØ
TÆMBØ6mo ago
I believe this behavior would have been emitted in previous semver-minor versions as well, so I find it odd you're only getting this TS error after updating. In any case, You'd want to type your interaction parameter as a MessageContextMenuCommandInteraction, which is a more narrowed ContextMenuCommandInteraction with additional types including getMessage() which is specific to message context menu commands
d.js docs
d.js docs6mo ago
:class: MessageContextMenuCommandInteraction @14.15.2 Represents a message context menu interaction.
P ђ ץ ร X
P ђ ץ ร XOP6mo ago
Ahhh, I did not notice this type existed. Thank you very much
Want results from more Discord servers?
Add your server