forever command

Asked 2 years ago, Updated 2 years ago, 132 views

I stumbled while creating a discord bot.I created it with node.js and run it with the forever command, but there is a bug(?) that sends a lot of replies.This increases every time you issue the forever command.

// Login Processing
const Discord=require('discord.js');
const client=new Discord.Client();
const token='Tokun';
client.on('ready',()=>{
    console.log('ready...');
});
// Curse to ignore Bot's own statement
client.on('message',message=>{
    if(message.author.bot){
        return;
    }
// ↓ Copy the code below here ↓
    if(message.content==='It's cold, isn't it?') {
        let channel = message.channel;
        let author=message.author.username;
        let reply_text=`It's cold, isn't it?`;
        message.reply(reply_text)
            .then(message=>console.log(`Sent message:${reply_text}`))
            .catch(console.error);
        return;
    }
    if(message.content==='It's hot, isn't it?') {
        let channel = message.channel;
        let author=message.author.username;
        let reply_text=`It's hot, isn't it?`;
        message.reply(reply_text)
            .then(message=>console.log(`Sent message:${reply_text}`))
            .catch(console.error);
        return;
    }
    if(message.content.match(/Good morning/)){
        message.channel.send(`${author}, good morning!`)
    }
    if(message.content.match(/discord.gg/)){
        message.delete(100)
    }
// ↑ Copy the code below here ↑
});
client.login(token);

"The ""good morning"" part is only once, but the ""cold weather"" part is repeated over and over again and again.What should I do?

javascript node.js discord

2022-09-29 22:27

1 Answers

Boot to node discord.js!

I'm sure it will work.


2022-09-29 22:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.