简体   繁体   中英

How to stop a message loop in discord.js?

I need some help to stop a loop in discord.js (using node). This is my piece of code:

client.on('message', message => {
  if (message.author.bot) return;
  if (message.channel.id === '601392330951491594') {
    if (message.content.startsWith('.idea')) {
      const clan = message.guild.channels.find(ch => ch.name === 'team-duty');
      const user = message.author;
      const messaggio = message.content.toString();
      const ListEmbed = new Discord.RichEmbed()
        .setTitle(`Messaggio di ${user.tag}`)
        .setDescription(messaggio)
      clan.send(ListEmbed);
      message.channel.bulkDelete(1)
      message.channel.send(`Messaggio inoltrato al gruppo staff (**${messaggio}**).`)
    }
  }
});

The problem here is that when I send a message starting with ".idea" the bot is keeping sending the messages in both channels. A strange thing is that when I send the message for the first time it sends just one message, and when I send the second/third message it starts looping.

With console.log(JSON.stringify(message)); , I get this error message:

   console.log(JSON.stringify(message));
                    ^

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Client.client.on.message (C:\Users\Kikkiu\Desktop\DiscordKikBot\index.js:23:21)
    at Client.emit (events.js:203:15)
    at MessageCreateHandler.handle (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:198:13)
    at Receiver.receiverOnMessage (C:\Users\Kikkiu\Desktop\DiscordKikBot\node_modules\ws\lib\websocket.js:789:20)

I solved this problem by moving this piece of code in my index.json, I don't even know the nature of this problem. I didn't edit the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM