#What error again Can you show the error
1 messages · Page 1 of 1 (latest)
const Levels = require("discord-xp");
module.exports = {
name: "— User Rank",
type: 2,
run: async (interaction) => {
const target = interaction.guild.members.cache.get(
interaction.targetId
);
const user = await Levels.fetch(target.id, interaction.guild.id); // Selects the target from the database.
if (!user) {
await interaction.reply({
content: "Seems like this user has not earned any xp so far.",
ephemeral: true,
});
} else {
await interaction.reply({
content: `__${
target.tag
}__\n\n> **Level**\n> :arrowup: ${
user.level
}\n\n> **Current XP**\n> :field: ${
user.xp
} / :field: ${Levels.xpFor(
user.level + 1
)}`,
ephemeral: true,
});
}
},
};
And error
Promise {
<rejected> TypeError: Cannot read properties of undefined (reading 'members')
at Object.run (C:\Users\neoai\Desktop\Depom\Neobot\commands\user\level\rank.js:7:36)
at Client.<anonymous> (C:\Users\neoai\Desktop\Depom\Neobot\events\guild\interactionCreate.js:29:12)
...
}```
Is this a context menu?
And to be sure what’s line 29?
running code
No what’s line 29
command.run(client, interaction, config);```
If that’s how you run the command then I’m guessing you missed your ordering of params
Would need to be async (client, interaction, config)
They aren’t, but the order matters
As if you do
Client, interaction
Then pass
Run async (interaction, client)
Interaction in your run function will be client
As you passed it to be that
Change it and see if it errors again
I see
@mild briar command is working but target.tag does not return user's username and discrim, eh
returns undefined xd
but other parts works well
Can you log target
Despite sounding similar there is a distinct difference between users and members in Discord:
• User: global Discord user data (global avatar, username, tag, id)
• GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.)
• Conversion: User ➞ GuildMember | GuildMember ➞ User
Also this ^
na na
Users have usernames members have nicknames
member.user.tag will return the tag, don’t think members have tags let me check
target.tag should've returned tho
Yh members don’t have tags, users do
Your target here is a member, not user
No
The variable, target, is a member
Despite sounding similar there is a distinct difference between users and members in Discord:
• User: global Discord user data (global avatar, username, tag, id)
• GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.)
• Conversion: User ➞ GuildMember | GuildMember ➞ User
I mean my variable's name is "user"
and it contains interaction.guild.member.cache from target variable
Right
so it is containing member
yes
yes a guild member is my target.
mhm
So use target.user.tag for their tag
No worries, you got it now?