简体   繁体   English

如何在discord.js中停止消息循环?

[英]How to stop a message loop in discord.js?

I need some help to stop a loop in discord.js (using node). 我需要一些帮助来停止discord.js中的循环(使用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. 这里的问题是,当我发送以“ .idea”开头的消息时,机器人会继续在两个通道中发送消息。 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)); 使用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. 我通过在index.json中移动这段代码解决了这个问题,我什至不知道这个问题的本质。 I didn't edit the code. 我没有编辑代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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