User ID to Username#Discrim #5699
-
I am trying to make a discord bot with discord.js, but I have a problem with the ban and kick commands. When a person says Here is my code: if (message.member.roles.cache.some(r => (r.name === "Moderator" || r.name === "Administrator"))) {
const member = message.mentions.users.first();
if (member) {
const MemberTarget = message.guild.members.cache.get(member.id);
const MemberString = MemberTarget.toString();
MemberTarget.kick();
message.channel.send(`${MemberString.tag} has been kicked successfully.`).catch(error => console.error(`Error occured; ${MemberString.tag} was not kicked.`));
} else {
message.channel.send("Sorry, you did not mention a valid user to kick.");
}
} else {
message.channel.send("Um.. it looks like you don't have the right permissions. In order to get the permissions, DM your server owner to kick the user.");
} But this happens when I run the bot: It should say AtharvNadkarni#4244, not "undefined". But nicely enough, my alt is removed from the server: But why does it say "undefined"? If I could, I would post the question on StackOverflow. But sadly, I cannot do it for 2 days because of my recent downvotes. Can you help me? I need text in my question, so don't say I have to go on Gist. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Because What you want to do is |
Beta Was this translation helpful? Give feedback.
Because
MemberString.tag
is similar to doing'81440962496172032'.tag
, and thetag
property does not exist in strings.What you want to do is
MemberTarget
.
user
.
tag
.