Discord repeating bot

4.6k Views Asked by At

I'm making my first Discord bot and the idea is that when a user sends a message to a channel, the bot simply repeats it. I have this set up, but the problem is that it goes into a loop and just keeps repeating. How can I break that so he repeats only once?

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

})

`

1

There are 1 best solutions below

0
Peter G On BEST ANSWER

You can use the id of the user that sent the message to make sure you're not repeating yourself. Assuming Commando has similar syntax to vanilla discord.js (it looks like it does), you can do this:

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);
    }

})