bot keeps repeating

Refresh

April 2019

Views

285 time

1

This discord bot keeps repeating what it just said concatenating two strings! Please help!

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

client.on('message', (message) => {
    if (message.content == prefix + 'test') {
        message.channel.sendMessage("```User Bot is a way to get more users in your discord server. When you first invite the bot, it will create a channel called #invites. You can put your message in #invites by doing the command *message <message>. Doing this command will make the bot broadcast your message and your invite link so all people with the bot in there #invites channel will get the message.```");
    } else if (message.content == prefix + 'setup') {
        message.channel.sendMessage("```To setup User Bot, you must join the user bot discord listed here. https://discord.gg/amuzrvr, then in #bots type your message!");
    } else if (message.channel.guild.name == 'UserBot' && message.channel.name == 'bots') {
        channel(message);
    }

});

function channel(message) {
    message.channel.sendMessage("***A server! " + message.content + "!***")
}

2 answers

0

As you have found out, the message event checks every single message inputted into the bot's guilds. To avoid it picking up the bot's messages, you can use

    if (msg.author.bot) return;

or something along those lines. :)

0

I found an answer, it was triggering every time the bot spoke cause the conditions were and are the same.