如何让我的 discord bot 复制并向每条用户写入的消息发送消息?

How do I make my discord bot copy and message every user written message?

所以我是 Javascript 和 Discord 机器人的新手。我有一个关于机器人的愚蠢想法。主要是为了惹恼我的朋友。但基本思想是它将复制他们的消息并用他们的消息进行响应。我遇到了一个问题,我无法让机器人回复一条以上的消息。

这是我的代码:

const Discord = require('discord.js');
const client = new Discord.Client();

// Logs into discord with the app's token
client.login('...');

// when logged in succesfully this code will run once
client.once('ready', () => {
    console.log('Ready!');
});

if(client.on) {
    client.once('message', function (message) {
        // Send message back on the same channel
        message.channel.send(message.content);
    }); 
}

我知道 client.once 只发送一次消息,但如果我将其更改为 client.on,它将向无限量发送相同的消息。任何帮助,将不胜感激。谢谢

您只需要阻止机器人响应自身即可。

client.on("message", (message) => {

    // Use this if you don't want the bot to respond to itself
    if (message.author.id == client.user.id) return;

    // Use this if you don't want the bot to respond to other bots (including itself)
    if (message.author.bot) return;

    message.channel.send(message.content);

});