最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Discord.js | You can only bulk delete messages that are under 14 days old - Stack Overflow

matteradmin6PV0评论

if there's messages over 14 days old and some that aren't 14 days old it does not delete the messages that aren't 14 days old and it sends an error is there a way to delete the messages that are not over 14 days old and leave the ones that are over 14 days old if you can't then can you help me make it stop sending an error and make it send a message saying "You can only bulk delete messages that are under 14 days old." in the channel instead of it showing a error in the console thanks.

const { Message } = require("discord.js");
const Client = require("../structures/Client");
module.exports = {
  name: `clear`,
  /**
   * @param {Client} client
   * @param {Message} message
   * @param {String[]} args
   */
  run: async (client, message, args) => {

    const msg = message;
    var amt = parseInt(args[0], 10);

    if(message.member.hasPermission(['MANAGE_MESSAGES'])) {
      if(!amt) {
        msg.channel.send(client.embed({ description: `${msg.author.username}! Please specify a amount of messages to delete`}));
      } else {
        if(amt > 100) {
          return message.channel.send(client.embed({ description: `You can only clear minimum of 100 messages per mand` }))
        } else {
          if(amt == 100) {
            msg.channel.bulkDelete(amt);
            msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
          } else {
            msg.channel.bulkDelete(amt + 1);
            msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
          }
        }
      }
    } else {
      if(message.member.hasPermission(['ADMINISTRATOR'])) {
        if(!amt) {
          msg.channel.send(client.embed({ description: `${msg.author.username}! Please specify a amount of messages to delete`}));
        } else {
          if(amt > 100) {
            return message.channel.send(client.embed({ description: `You can only clear minimum of 100 messages per mand` }))
          } else {
            if(amt == 100) {
              msg.channel.bulkDelete(amt);
              msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
            } else {
              msg.channel.bulkDelete(amt + 1);
              msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
            }
          }
        }
      } else {
        msg.channel.send(client.embed({ description: `${msg.author.username}! You do not have permission to run that mand.`}));
      }
    }



  },
  timeout: 1500
}

if there's messages over 14 days old and some that aren't 14 days old it does not delete the messages that aren't 14 days old and it sends an error is there a way to delete the messages that are not over 14 days old and leave the ones that are over 14 days old if you can't then can you help me make it stop sending an error and make it send a message saying "You can only bulk delete messages that are under 14 days old." in the channel instead of it showing a error in the console thanks.

const { Message } = require("discord.js");
const Client = require("../structures/Client");
module.exports = {
  name: `clear`,
  /**
   * @param {Client} client
   * @param {Message} message
   * @param {String[]} args
   */
  run: async (client, message, args) => {

    const msg = message;
    var amt = parseInt(args[0], 10);

    if(message.member.hasPermission(['MANAGE_MESSAGES'])) {
      if(!amt) {
        msg.channel.send(client.embed({ description: `${msg.author.username}! Please specify a amount of messages to delete`}));
      } else {
        if(amt > 100) {
          return message.channel.send(client.embed({ description: `You can only clear minimum of 100 messages per mand` }))
        } else {
          if(amt == 100) {
            msg.channel.bulkDelete(amt);
            msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
          } else {
            msg.channel.bulkDelete(amt + 1);
            msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
          }
        }
      }
    } else {
      if(message.member.hasPermission(['ADMINISTRATOR'])) {
        if(!amt) {
          msg.channel.send(client.embed({ description: `${msg.author.username}! Please specify a amount of messages to delete`}));
        } else {
          if(amt > 100) {
            return message.channel.send(client.embed({ description: `You can only clear minimum of 100 messages per mand` }))
          } else {
            if(amt == 100) {
              msg.channel.bulkDelete(amt);
              msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
            } else {
              msg.channel.bulkDelete(amt + 1);
              msg.channel.send(client.embed({ description: `${msg.author.username}! You cleared ${amt} messages`})).then(m => { m.delete({ timeout: 3000 }); }).catch(err => { console.log(err); })
            }
          }
        }
      } else {
        msg.channel.send(client.embed({ description: `${msg.author.username}! You do not have permission to run that mand.`}));
      }
    }



  },
  timeout: 1500
}
Share Improve this question asked Oct 28, 2020 at 21:45 RareHyperIonRareHyperIon 111 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

The messages that are bulk deletable in the Discord API are messages less than 14 days old. That is an API limitation, not the library limitation.

The library can filter out messages older than 14 days, like so.

message.channel.bulkDelete(number, true);

You need to set the filterOld parameter to true to automatically filter out old messages and not throw an error.

Post a comment

comment list (0)

  1. No comments so far