Help with banning member from command

I am running into the error (displayed in the image) whenever I run my ban command. Here is the code for the ban command:
const guild = client.guilds.cache.get("940438220959789097");

const user = interaction.options.getMember("user");
const reason = interaction.options.getString("reason");

if(user.bannable){
guild.members.ban(user);
} else {
interaction.reply({
content: `${user.tag} is not Bannable!`,
ephemeral: true
})
}
const guild = client.guilds.cache.get("940438220959789097");

const user = interaction.options.getMember("user");
const reason = interaction.options.getString("reason");

if(user.bannable){
guild.members.ban(user);
} else {
interaction.reply({
content: `${user.tag} is not Bannable!`,
ephemeral: true
})
}
12 Replies
d.js docs
d.js docsβ€’3y ago
β€’ What's your exact discord.js npm list discord.js and node node -v version? β€’ Post the full error stack trace, not just the top part! β€’ Show your code! β€’ Explain what exactly your issue is. β€’ Not a discord.js issue? Check out #useful-servers.
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
(sorry about the code not being formatted correctly, Discord bugged)
MrMythical
MrMythicalβ€’3y ago
you need the Guilds intent
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
Oh Quick question, why is user.tag undefined
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
user is set to a required option in the command
MrMythical
MrMythicalβ€’3y ago
user is a GuildMember use user.user.tag, and maybe even rename user to something more accurate, like member
μ‘°μ•„μ˜€
Just to complement
d.js docs
d.js docsβ€’3y ago
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 didn't notice that the interaction option would return a GuildMember thats all Thanks for the help though
Want results from more Discord servers?
Add your server