I am making it so if I type @Wide#9256 it will respond
here is my code:
if (message.mentions.members.first() !== undefined) {
if (message.mentions.members.first().id === bot.user.id) {
const embed = new Discord.MessageEmbed()
.setTitle("Prefix")
.setDescription('My Prefix is "!"')
.setFooter('Type !help for more information')
.setThumbnail(bot.user.displayAvatarURL())
.setColor('RANDOM')
message.channel.send(embed)
}
}
But in this code it also respond if I said like "Hey @Wide#9256 h", I want it to respond if its only "@Wide#9256" and nothing else.
I tried
if (message.content === message.mentions.members.first().id === bot.user.id)
Does not work, thank you in advance
Corrected Code:
if(message.mentions.members.first() && message.content.split(' ').length === 1) {
// Your code here
}
How it works:
The message.content.split(' ')
returns an array of all the parts of the message as separate elements, separated by ' '
. For more information: https://www.w3schools.com/jsref/jsref_split.asp
In that case, you'll just have to directly compare the message content to the raw mention format ( <@ID>
)
// this leaves no spaces for anything before or after the mention
if (message.content === bot.user.toString()) { // generates mention format
// ...
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.