Lookup Error

Hey! I upgraded to the newest discordjs and one of my commands are not working anymore. I build in logs & that is the output:
discordInfo command triggered.
User has the required permission.
Validating channel types...
(node:22448) Warning: Supplying "ephemeral" for interaction response options is deprecated. Utilize flags instead.
Reply deferred.
Fetching user: supersayajin7 (ID: 1135769063365296191)
Error occurred in discordInfo command: TypeError: Cannot read properties of undefined (reading 'fetchGuildMember')
discordInfo command triggered.
User has the required permission.
Validating channel types...
(node:22448) Warning: Supplying "ephemeral" for interaction response options is deprecated. Utilize flags instead.
Reply deferred.
Fetching user: supersayajin7 (ID: 1135769063365296191)
Error occurred in discordInfo command: TypeError: Cannot read properties of undefined (reading 'fetchGuildMember')
private async fetchGuildMember(
interaction: UserContextMenuCommandInteraction,
user: User
): Promise<GuildMember | null> {
try {
console.log(`Fetching guild member with ID: ${user.id}`);
return (await interaction.guild?.members.fetch(user.id)) || null;
} catch (error) {
console.error("Error while fetching guild member:", error);
return null;
}
}
private async fetchGuildMember(
interaction: UserContextMenuCommandInteraction,
user: User
): Promise<GuildMember | null> {
try {
console.log(`Fetching guild member with ID: ${user.id}`);
return (await interaction.guild?.members.fetch(user.id)) || null;
} catch (error) {
console.error("Error while fetching guild member:", error);
return null;
}
}
this code worked and now it says the error
12 Replies
d.js toolkit
d.js toolkit3w 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!
cRiZZly
cRiZZlyOP3w ago
Node: v20.14.0 discordjs: ├─┬ @discordx/[email protected] │ └── [email protected] deduped ├── [email protected] └─┬ [email protected] └── [email protected] deduped
treble/luna
treble/luna3w ago
Sounds like you are calling your fetchGuildMember on something thats undefined whilst it is a standalone function
cRiZZly
cRiZZlyOP3w ago
i mean it worked 2-3 days ago and since today its not working but no const member = await this.fetchGuildMember(interaction, user);
NyR
NyR3w ago
Then sounds like your this is undefined there, you maybe losing your this context or there maybe some other cause Would be good if you showed your full code
cRiZZly
cRiZZlyOP3w ago
@Discord()
export class LookupDiscordInfoCommand {
@ContextMenu({
name: "Lookup Discord-Informations",
type: ApplicationCommandType.User,
})
async discordInfo(
interaction: UserContextMenuCommandInteraction
): Promise<void> {
try {
if (
!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)
) {
await interaction.reply({
content: "❌ You do not have permission to use this.",
ephemeral: true,
});
return;
}
if (!validateChannelTypes(interaction)) return;

await interaction.deferReply({ ephemeral: false });
const user = interaction.targetUser;
const member = await this.fetchGuildMember(interaction, user);
const userEmbed = await this.createUserEmbed(user, member, interaction);

const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("Server-Kick")
.setLabel("Server-Kick")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId("Server-Ban")
.setLabel("Server-Ban")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId("User-Timeout")
.setLabel("Timeout")
.setStyle(ButtonStyle.Danger)
);

if (interaction.replied || interaction.deferred) {
await interaction.editReply({
embeds: [userEmbed],
components: [buttonRow],
});
} else {
await interaction.followUp({
content: "An error occurred while fetching user information.",
ephemeral: true,
});
}
} catch (error) {
await interaction.followUp({
content: "An error occurred while fetching user information.",
ephemeral: true,
});
}
}

private async fetchGuildMember(
interaction: UserContextMenuCommandInteraction,
user: User
): Promise<GuildMember | null> {
try {
return (await interaction.guild?.members.fetch(user.id)) || null;
} catch (error) {
return null;
}
}

private async createUserEmbed(
user: User,
member: GuildMember | null,
interaction: UserContextMenuCommandInteraction
): Promise<EmbedBuilder> {
const accountCreatedTimestamp = formatTimestamp(user.createdAt);
const joinedServerTimestamp = member?.joinedAt
? formatTimestamp(member.joinedAt)
: "N/A";

return new EmbedBuilder()
.setColor(EMBED_CONFIG.COLOR)
.setAuthor({
name: "Lizard - Account Informations",
iconURL: interaction.client.user?.avatarURL() || undefined,
})
.setDescription(`**Member:** <@${user.id}>`)
.setThumbnail(user.avatarURL({ size: 128 }) || null)
.addFields(
{ name: "👤 Name", value: user.username || "N/A", inline: true },
{ name: "🆔 ID", value: user.id, inline: true },
{
name: "📅 Account Created",
value: accountCreatedTimestamp,
inline: true,
},
{ name: "📅 Joined At", value: joinedServerTimestamp, inline: true },
{
name: "🔗 Profile Picture",
value: `[Picture Link](${user.avatarURL()})`,
inline: true,
}
)
.setFooter({
text: "Lizard - Account Informations",
iconURL: interaction.client.user?.avatarURL() || undefined,
})
.setTimestamp();
}
@Discord()
export class LookupDiscordInfoCommand {
@ContextMenu({
name: "Lookup Discord-Informations",
type: ApplicationCommandType.User,
})
async discordInfo(
interaction: UserContextMenuCommandInteraction
): Promise<void> {
try {
if (
!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)
) {
await interaction.reply({
content: "❌ You do not have permission to use this.",
ephemeral: true,
});
return;
}
if (!validateChannelTypes(interaction)) return;

await interaction.deferReply({ ephemeral: false });
const user = interaction.targetUser;
const member = await this.fetchGuildMember(interaction, user);
const userEmbed = await this.createUserEmbed(user, member, interaction);

const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("Server-Kick")
.setLabel("Server-Kick")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId("Server-Ban")
.setLabel("Server-Ban")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId("User-Timeout")
.setLabel("Timeout")
.setStyle(ButtonStyle.Danger)
);

if (interaction.replied || interaction.deferred) {
await interaction.editReply({
embeds: [userEmbed],
components: [buttonRow],
});
} else {
await interaction.followUp({
content: "An error occurred while fetching user information.",
ephemeral: true,
});
}
} catch (error) {
await interaction.followUp({
content: "An error occurred while fetching user information.",
ephemeral: true,
});
}
}

private async fetchGuildMember(
interaction: UserContextMenuCommandInteraction,
user: User
): Promise<GuildMember | null> {
try {
return (await interaction.guild?.members.fetch(user.id)) || null;
} catch (error) {
return null;
}
}

private async createUserEmbed(
user: User,
member: GuildMember | null,
interaction: UserContextMenuCommandInteraction
): Promise<EmbedBuilder> {
const accountCreatedTimestamp = formatTimestamp(user.createdAt);
const joinedServerTimestamp = member?.joinedAt
? formatTimestamp(member.joinedAt)
: "N/A";

return new EmbedBuilder()
.setColor(EMBED_CONFIG.COLOR)
.setAuthor({
name: "Lizard - Account Informations",
iconURL: interaction.client.user?.avatarURL() || undefined,
})
.setDescription(`**Member:** <@${user.id}>`)
.setThumbnail(user.avatarURL({ size: 128 }) || null)
.addFields(
{ name: "👤 Name", value: user.username || "N/A", inline: true },
{ name: "🆔 ID", value: user.id, inline: true },
{
name: "📅 Account Created",
value: accountCreatedTimestamp,
inline: true,
},
{ name: "📅 Joined At", value: joinedServerTimestamp, inline: true },
{
name: "🔗 Profile Picture",
value: `[Picture Link](${user.avatarURL()})`,
inline: true,
}
)
.setFooter({
text: "Lizard - Account Informations",
iconURL: interaction.client.user?.avatarURL() || undefined,
})
.setTimestamp();
}
NyR
NyR3w ago
How do you call discordInfo? If you destructure it from the instance, that could explain the issue or it maybe related to your decorator
cRiZZly
cRiZZlyOP3w ago
its a context menu command
NyR
NyR3w ago
I see that. Not what I asked though
cRiZZly
cRiZZlyOP3w ago
Is it related to my framework also discordx or how? cuz im not an expert and idk why it broke cuz i didnt change smth it has to do with the update but idk what. my old bot who has the same command its working there. the new command just has buttons and the logic for that
treble/luna
treble/luna3w ago
none of it looks to be related to djs though
cRiZZly
cRiZZlyOP3w ago
idk somehow after reinstall of both npm packages, its working again.

Did you find this page helpful?