Skip to content
Advertisement

I’m having an issue with adding an “Auto-Moderating” feature on my Discord bot

G’day, I really need some help with the “Auto-Moderation” feature that I want to include in my very first Discord Bot, which is coded in JavaScript. Also, I am really new to this programming language and the discord.js itself, so I don’t really know how to use all the arguments properly.

Whatever, the point is, I want my bot to analyze the messages sent by every member of my Discord Server and look out for offensive or inappropriate words in said messages. If it finds at least one, it will send a message Mentioning the member that sent said message along with a warning command.

I got the bot to correctly register the members username whenever it detects the offensive word and to send a message with said name, the problem is that it only writes @(username), without getting to actually mention and warn said member. With no other information I can bring to you, I’ll leave you with the code:

client.on('message', message => {
    if (message.toString().toLowerCase().includes("idiot")) {
        var y = message.author.username
        message.channel.send("!warn " + "@" + y + "Use of offensive language.");
    }
});

I would be very grateful if you could help me out with this little issue. Thanks for taking the time to read this, have a nice day.

Advertisement

Answer

You can mention the user with the syntax <@USERID>.

Also, it’s better to get the content of the message instead of .toString().

client.on('message', message => {
    if (message.content.toLowerCase().includes("idiot")) {
        message.channel.send("!warn <@" + message.author.id + "> Use of offensive language.");
    }
});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement