admin管理员组

文章数量:1025457

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.

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.

本文标签: javascriptDiscordjsYou can only bulk delete messages that are under 14 days oldStack Overflow