反攻字命令垃圾邮件日志

时间:2020-10-18 17:27:57

标签: javascript discord discord.js bots

我想做一个反攻词机器人,但是当您说出这个词时,它会将ive设置为它的频道发送垃圾邮件。

它会在嵌入了嵌入内容的情况下向通道发送垃圾邮件,甚至还会发送日志消息-(${message.author.tag} said an offensive word. ~~ Word : ${message.content}

代码


client.on('message', message =>{
        if (message.content.includes(forbidenWords[i])) {
        
    message.channel.send({embed: {
        color: 16711680,
        author: {
          name: 'hiiiii says -',
          icon_url: 'https://cdn.discordapp.com/avatars/754479647466717234/a_0e2811a46da6c10576755f41d9d970bb.gif?size=128'
        },
        title: "**The word you said was forbiden.**",
        description: "*Continued language like this will result in a **mute.***",

        footer: {
          icon_url: 'https://cdn.discordapp.com/avatars/754479647466717234/a_0e2811a46da6c10576755f41d9d970bb.gif?size=128' ,
          text: "Made by PixelIGPM8!"

         
        }
        
        
      }


    });
    message.delete()


    client.channels.cache.get(`764449288985772072`).send(`${message.author.tag} said an offensive word. ~~ Word : ${message.content}`)

    break;



}```

2 个答案:

答案 0 :(得分:1)

您的代码一团糟,所以我为您修补了它。我假设forbiddenWords是不允许的字词字符串数组。 另外,您必须检查作者是否是机器人,以免对自己做出回应

client.on('message', message => {
    if (msg.author.bot) { return }
    else if (new RegExp(forbiddenWords.join("|")).test(message.content)) {
        message.channel.send({
            embed: {
                color: 16711680,
                author: {
                    name: 'hiiiii says -',
                    icon_url: 'https://cdn.discordapp.com/avatars/754479647466717234/a_0e2811a46da6c10576755f41d9d970bb.gif?size=128'
                },
                title: "**The word you said was forbiden.**",
                description: "*Continued language like this will result in a **mute.***",
                footer: {
                    icon_url: 'https://cdn.discordapp.com/avatars/754479647466717234/a_0e2811a46da6c10576755f41d9d970bb.gif?size=128',
                    text: "Made by PixelIGPM8!"
                }
            }
        });
        message.delete();
        client.channels.cache.get(`764449288985772072`).send(`${message.author.tag} said an offensive word. ~~ Content : ${message.content}`)
    }
});

我已经修复了“禁止”的拼写,因此您可能需要在给定代码之外更改变量的名称。

答案 1 :(得分:0)

它不断重复发送消息有两个原因。

第一个是您不检查消息是否来自机器人,第二个是您的机器人然后重复单词再次触发消息。

要解决此问题,您需要做的就是在检查单词之前将其放入。

if (message.author.bot) return;