[TS] Argument of type 'GuildMember | APIInteractionGuildMember | null'

full error
[Event: ready] [Uncaught Error] src/cmds/me.ts:11:36 - error TS2345: Argument of type 'GuildMember | APIInteractionGuildMember | null' is not assignable to parameter of type 'GuildMember'.
Type 'null' is not assignable to type 'GuildMember'.

11 const perm = getPermissionRank(inter.member)
~~~~~~~~~~~~
[Event: ready] [Uncaught Error] src/cmds/me.ts:11:36 - error TS2345: Argument of type 'GuildMember | APIInteractionGuildMember | null' is not assignable to parameter of type 'GuildMember'.
Type 'null' is not assignable to type 'GuildMember'.

11 const perm = getPermissionRank(inter.member)
~~~~~~~~~~~~
everything seems fine except line 11
import { GuildMember } from "discord.js";

export function getPermissionRank(member: GuildMember): Number{
if(!(member instanceof GuildMember)) throw new Error('Argument 1 is not supported. (supported: GuildMember)');

// the above code may be causing this issue, the rest i know is fine
import { GuildMember } from "discord.js";

export function getPermissionRank(member: GuildMember): Number{
if(!(member instanceof GuildMember)) throw new Error('Argument 1 is not supported. (supported: GuildMember)');

// the above code may be causing this issue, the rest i know is fine
npm v.9.6.7 node v.18.3.0 discord.js v14.11.0
5 Replies
d.js toolkit
d.js toolkit16mo 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
duck16mo ago
<Interaction>.member may not be a GuildMember if the interaction was received in a dm or from a guild that isn't cached you'd want to typeguard with <Interaction>.inCachedGuild() if this is done prior to execute being called, then you'd want to specify the generic <"cached"> for your interaction's type as a side note, CommandInteraction is for all application command interactions, including context menu commands ChatInputCommandInteraction is for slash commands if you're typeguarding the interaction somewhere before execute is called, you can use the <Interaction>.isChatInputCommand() typeguard
doqe
doqeOP16mo ago
i used .isChatInputCommand() in my event handler
duck
duck16mo ago
then that's perfectly ok I just wanted to mention since you typed inter as CommandInteraction
doqe
doqeOP16mo ago
oh thx also thx for the help it worked
Want results from more Discord servers?
Add your server