简体   繁体   中英

Discord.js: How to make bot log if someone was swearing?

I am node.js bot coder and curious how can I make my bot log in a specific channel if someone said bad word. My code is:

client.on('message', message => {
    if (message.author.bot) return;
    let rudeWords = ["censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored", "censored"];
    if (rudeWords.some(word => message.toString().toLowerCase().includes(word))) {
        message.delete()
        message.reply('do not use that word here, thank you.').then(msg => 
        {msg.delete({ timeout: 3000 })
    })
}})

What should I add to this for bot to log if someone sweared? Help pls <3

Array.Includes()

 let rudeWords = ["censored", "censored", "censored"]; var message = "censored" console.log(rudeWords.includes(message.toLowerCase()));

You can send messages to a specific channel either by find or get method. Find requires an arrow function, whereas get required the ID of the channel as a String.

Eg : by get method:

let logChannel = message.guild.channels.cache.get('the-channel-id');
logChannel.send("Someone sweared");

by find method:

let logChannel = message.guild.channels.cache.find(channel=>channel.name==='the-channel-name');
logChannel.send("Someone sweared");

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM