Reputation: 69
I've started my bot after a while and for some reason the mention command is not working. Code and response to the command is below:
client.on('message', message => {
if (message.content.startsWith('L!bite')) {
let targetMember = message.mentions.members.first();
if (!targetMember) return message.reply('you need to tag a user in order to bite them!!');
// message goes below!
message.channel.send(`${targetMember.user}, You just got a bitten!`);
message.channel.send({files:["./nom/"]})
//let embed = new Discord.RichEmbed()
//embed.setImage(`https://media1.tenor.com/images/4f5666861516073c1c8015b2af7e2d15/tenor.gif?itemid=14720869`)
message.channel.send(embed);
}
});
Response on Discord: (it does picks itself up as a user but not anyone else)
Β·._.β’π πΉπ΅πΌπΏππΏπΌπ’πΌπ
πΏ πβ’._.Β·Today at 1:18 PM
L!bite @Β·._.β’π πΉπ΅πΌπΏππΏπΌπ’πΌπ
πΏ πβ’._.Β·
._.Β·ππΉπ΅πΌπΏβ‘ππΎππΈπ£πΒ·._.BOT Today at 1:18 PM
@Β·._.β’π πΉπ΅πΌπΏππΏπΌπ’πΌπ
πΏ πβ’._.Β·, you need to tag a user in order to bite them!!
I'm just confused on why it's saying that I'm or other people are not users, but it picks up itself? E.g.:
Β·._.β’π πΉπ΅πΌπΏππΏπΌπ’πΌπ
πΏ πβ’._.Β·Today at 1:18 PM
L!bite @._.Β·ππΉπ΅πΌπΏβ‘ππΎππΈπ£πΒ·._.
._.Β·ππΉπ΅πΌπΏβ‘ππΎππΈπ£πΒ·._.BOT Today at 1:18 PM
@._.Β·ππΉπ΅πΌπΏβ‘ππΎππΈπ£πΒ·._., You just got a bitten!
GIF HERE
Upvotes: 0
Views: 193
Reputation: 1196
Alternatively, there's already a parameter you can implement in your code where it can automatically check if the message came from a bot. Although, this process may not work if you want to have other bots automatically tag it, but I think that's unlikely.
if (message.author.bot) return;
FYI, not sure of which version of discord.js you're using, but the embed naming convention has changed. Instead of RichEmbed()
, you should use MessageEmbed()
.
So the place you would implement this is right after your first if
conditional block, like this:
if (message.content.startsWith('L!bite')) {
//the thing that checks if the user who posted was the bot
if (message.author.bot) return;
Hopefully this helps!
Upvotes: 0
Reputation: 921
Try converting the message.mentions.members
to array and then filter your bot! -
const mentions = message.mentions.members.array() // will return members array of GuildMember class
const firstMention = mentions.filter(mention=> !mention.user.id === "BOT_ID")[0]
Upvotes: 1