【问题标题】:Discord repeating bot [duplicate]不和谐重复机器人[重复]
【发布时间】:2018-02-25 13:00:23
【问题描述】:

我正在制作我的第一个 Discord 机器人,其想法是当用户向频道发送消息时,机器人只会重复它。我有这个设置,但问题是它进入一个循环并不断重复。我怎样才能打破它,让他只重复一次?

const Commando = require('discord.js-commando');
const bot = new Commando.Client();
bot.on('message', (message) => {
     if (message.content){ 
        message.channel.sendMessage(message.content);
    }

})

`

【问题讨论】:

  • 最有可能的是,一旦您的机器人看到它重复的消息,它就会自我重复。
  • 我知道是这样,我的问题是如何打破它,让它只重复一次?

标签: javascript node.js discord discord.js


【解决方案1】:

您可以使用发送消息的用户的id,以确保您不会重复自己。假设 Commando 具有与 vanilla discord.js 相似的语法(看起来确实如此),您可以这样做:

const Commando = require('discord.js-commando');
const bot = new Commando.Client();
bot.on('message', (message) => {
     if (message.author.id !== bot.user.id && message.content){ 
        message.channel.sendMessage(message.content);
    }

})

【讨论】:

    猜你喜欢
    • 2021-02-01
    • 1970-01-01
    • 2019-12-18
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 2020-09-23
    • 1970-01-01
    相关资源
    最近更新 更多