FBILOLIGIRL
FBILOLIGIRL

Reputation: 69

discord.js mention command not picking up users but picks up itself

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

Answers (2)

PerplexingParadox
PerplexingParadox

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

Stars Tracker
Stars Tracker

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

Related Questions