简体   繁体   English

Discord.js:如果有人说脏话,如何制作机器人日志?

[英]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.我是 node.js 机器人编码器,我很好奇如果有人说坏话,我怎样才能让我的机器人登录特定频道。 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请帮助<3

Array.Includes() 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.您可以通过findget方法将消息发送到特定通道。 Find requires an arrow function, whereas get required the ID of the channel as a String. Find 需要箭头 function,而 get 需要通道 ID 作为字符串。

Eg : by get method:例如通过 get 方法:

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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