Reputation: 7
I have tried to make a hug command on discord to hug the mentioned user. I set up a command to check if there has been a user mentioned. If I do not mention a user, it works as intended, but when mentioning a user, it outputs the same thing. Here is my code:
if (message.mentions.users.length > 1) {
const hug = new Discord.MessageEmbed()
.setAuthor(`${message.mentions.users.first().username} got a hug from ${message.author.username}!`, `${message.author.avatarURL({ dynamic:true })}`)
.setImage(hugs[hugged])
.setColor('#ffb9f4')
message.channel.send(hug);
} else {
message.channel.send('Please mention a user to hug!');
};
I don't think anything else should be needed but let me know
Upvotes: 0
Views: 106
Reputation: 51
Your condition checks if there is more than one user tagged, but you can check if there is any tagged users with
if (message.mentions.users == true)
Second problem is that users is a collection so you have to use .size instead of .length
if (message.mentions.users.size > 0)
Both are good.
Upvotes: 1
Reputation: 957
If you are doing it in a guild, I'm pretty sure that all mentions are to a GuildMember, try setting your if statement to
if(message.mentions.members.length > 1 || message.mentions.users.length > 1)
Upvotes: 0