即使将Interval设置为60000(1分钟),Discord bot也会一次发送多条消息

时间:2020-07-20 16:39:20

标签: javascript node.js discord discord.js

const Discord = require('discord.js');
const { Client, MessageAttachment } = require('discord.js');
const client = new Discord.Client();


client.once('ready', () => {
    console.log("Ready!")
})

client.on('message', message =>{
    msg = message.content.toLowerCase();
   
    const generalBotTesting = '598918505605234723';
    function cheekibreeki(){
        client.channels.cache.get(generalBotTesting).send("Cheeki Breeki")    
    }
    setInterval(cheekibreeki,60000)
}
)

client.login(process.env.token);

即使设置“间隔”值用于每分钟仅发送一次邮件,我的机器人也向垃圾邮件发送了垃圾邮件

1 个答案:

答案 0 :(得分:1)

您要为每条收到 的消息开始一个新的间隔,您要做的是在客户端连接到Discord API时开始一个间隔。

const Discord = require('discord.js');
const { Client, MessageAttachment } = require('discord.js');
const client = new Discord.Client();


client.once('ready', () => {
    console.log("Ready!")
    
    setInterval(cheekibreeki, 60 * 1000)
})

const generalBotTesting = '598918505605234723';
    
function cheekibreeki(){
    client.channels.cache.get(generalBotTesting).send("Cheeki Breeki")    
}



client.on('message', message =>{
    msg = message.content.toLowerCase();
})



client.login(process.env.token);