简体   繁体   English

我在 Discord 机器人上添加“自动调节”功能时遇到问题

[英]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. G'day,我真的需要一些“自动审核”功能的帮助,我想在我的第一个 Discord Bot 中包含该功能,该功能编码为 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.另外,我对这种编程语言和 discord.js 本身真的很陌生,所以我真的不知道如何正确使用所有 arguments。

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.无论如何,重点是,我希望我的机器人分析我的 Discord 服务器的每个成员发送的消息,并在所述消息中寻找冒犯性或不恰当的词。 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.感谢您花时间阅读本文,祝您有美好的一天。

You can mention the user with the syntax <@USERID> .您可以使用语法<@USERID>提及用户。

Also, it's better to get the content of the message instead of.toString().另外,最好是获取消息的内容而不是.toString()。

client.on('message', message => {
    if (message.content.toLowerCase().includes("idiot")) {
        message.channel.send("!warn <@" + message.author.id + "> Use of offensive language.");
    }
});
client.on("message", message => {
    if (message.content.toLowerCase().includes("idiot")) {
        message.channel.send(`!warn ${message.author.member} Use of offensive language.`);
    }
});

Or just using message.author.member that will do the same thing.或者只是使用message.author.member会做同样的事情。 You put your code between this symbol " ` " rather than double quote to make code more simple to read.您将代码放在这个符号“`”之间而不是双引号以使代码更易于阅读。 You can add a variable by using ${variable} .您可以使用${variable}添加变量。

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

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