简体   繁体   中英

discord.js unlimited purge command

Is there a way to make this better? I'm trying to make unlimited purge command... But it seems like message.channel.messages.cache only gets message the time you used it and I don't really know how to make it better. The bot will just lag for a long time... and cycle wont break because of that.

    for (let i = 1; i <= amount/100; i++) {
           let messagecount = message.channel.messages.cache.size
           if(messagecount<=5){ 
              console.log("break")
                break}
           message.channel.bulkDelete(100)
        }
      }

According to the Discord API docs , you can't delete messages older than 2 weeks through the Discord API, and neither can you with more than 100 messages. This is not a limitation you should/would want to break, and you may encounter the risk of being ratelimited . Of course, you could loop this, as you tried, but the ratelimit is still here. If I were you and wanted to delete the messages this bad, I would either call the command multiple times, or loop the bulkDelete with a cooldown (2000ms would be enough, I guess?).

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