'Need help fixing a Discord Bot command

I'm making a >bean {user.mention} command, which the bot would respond with {user.mention} has been beaned! I want the responce to not ping the user, but just say the users username and hashtag (ex: Example#1234).

Here is my code (node.js v12):

  if (message.content.startsWith('!bean ')){
    message.channel.send('${user} has been beaned!')
  }
})


Solution 1:[1]

Read docs

Coming to your question

client.on("message", message =>{
    if(message.content.startsWith('!bean')){
        let target = message.mentions.users.first()
        if(!target) {
            message.reply(`Mention a user to bean!`)
        } else {
        message.channel.send(`${target.username} has been beaned`)
    //.username returns their username like 'Wanda' & .tag returns their tag like 'Wanda#1234'
    }
    }
})

Some things you can change to make your future coding organised

• Use a command handler

2 things you must change

• Update to discord.js v13 since v12 is deprecated

• Update your node to v16 or higher

In-case you need help knowing initial setup changes, read the guide

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1