interaction.options.getMember() not definable?

Somehow interaction.options.getMember() is not valid... While on the Discord.js docs it is. I already made Member to be outputted to a message, and it says @Jarvo, so it should be correct...
import { Command } from "@sapphire/framework";

export class RenameCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
});
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("setnickname")
.setDescription("Let the bot rename someone")
.addUserOption(option =>
option.setName('member')
.setDescription('For what member is it?')
.setRequired(true)
)
.addStringOption(option =>
option.setName('name')
.setDescription('What will their new name be?')
.setRequired(true)
);
);
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
const Member = interaction.options.getMember('member')
const NewName = interaction.options.getString('name')

await interaction.reply({ content: `Done!`, ephemeral: true})
}
};
import { Command } from "@sapphire/framework";

export class RenameCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
});
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("setnickname")
.setDescription("Let the bot rename someone")
.addUserOption(option =>
option.setName('member')
.setDescription('For what member is it?')
.setRequired(true)
)
.addStringOption(option =>
option.setName('name')
.setDescription('What will their new name be?')
.setRequired(true)
);
);
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
const Member = interaction.options.getMember('member')
const NewName = interaction.options.getString('name')

await interaction.reply({ content: `Done!`, ephemeral: true})
}
};
Solution:
Oh. Nevermind. I fixed it already.
Jump to solution
9 Replies
Solution
Jarvo
Jarvo•11mo ago
Oh. Nevermind. I fixed it already.
Jarvo
JarvoOP•11mo ago
Nvm Issue is not resolved. Error:
Property 'setNickname' does not exist on type 'GuildMember | APIInteractionDataResolvedGuildMember'.
Property 'setNickname' does not exist on type 'APIInteractionDataResolvedGuildMember'.
Property 'setNickname' does not exist on type 'GuildMember | APIInteractionDataResolvedGuildMember'.
Property 'setNickname' does not exist on type 'APIInteractionDataResolvedGuildMember'.
And the Discord.js mods told me it's a sapphire problem 🙄 When I do Member. I get: - addChannelOption - addChannelTypes - addComponents - addFields and more Fixed*
Favna
Favna•11mo ago
Well that's dumb because it's not pepeHmm @vladdy pls educate your djs buddies pepeCry The problem here is that getMember can either be the DJS Class or an API object. That's just how discord.js's types work. The way to ensure that it's a GuildMember is by using type guards. In fact we export isGuildMember from @sapphire/discord.js-utilities (note the name... discord.js) for this very purpose
const member = interaction.options.getMember('member');

if (!isGuildMember(member)) throw new Error('kablooie');

// TS will now know that it's a GuildMember
const member = interaction.options.getMember('member');

if (!isGuildMember(member)) throw new Error('kablooie');

// TS will now know that it's a GuildMember
(Handle that error in a better way ofc)
vladdy
vladdy•11mo ago
or cast your interaction as being cached if you know its always cached
Jarvo
JarvoOP•11mo ago
@Favna it's already fixed. Seemed like VSC messed up... We restarted VSC and it worked again.
Favna
Favna•11mo ago
Either way that casting as cached or using the type guards is still the way to go
Jarvo
JarvoOP•11mo ago
we fetch the member
Favna
Favna•11mo ago
Yah then it's cached
Jarvo
JarvoOP•11mo ago
yup
Want results from more Discord servers?
Add your server