#channel.bulkDelete not working in some channels

1 messages · Page 1 of 1 (latest)

jolly agate
cerulean spindle
#

Show the code, it may be permission error

#

@jolly agate you don't need to create a thread for every question

atomic citrus
#
const { CommandInteraction, MessageEmbed } = require('discord.js');

module.exports = {
  name: 'clear',
  description: 'Deletes messages',
  permissions: ['MANAGE_MESSAGES'],
  options: [
    {
      name: 'amount',
      description:
        'Select the amount of message to delete from a channel or a target.',
      type: 'NUMBER',
      required: true,
    },
    {
      name: 'target',
      description: 'Select a target to clear their messages.',
      type: 'USER',
      required: false,
    },
  ],
  /**
   *
   * @param {CommandInteraction} interaction
   */
  async execute(interaction) {
    const { channel, options } = interaction;

    const Amount = options.getNumber('amount');
    const Target = options.getMember('target');

    const Messages = await channel.messages.fetch();

    const Response = new MessageEmbed().setColor('DARK_RED');

    if (Target) {
      let i = 0;
      const filtered = [];
      Messages.filter((message) => {
        if (message.author.id === Target.id && Amount > i) {
          filtered.push(message);
          i++;
        }
      });

      await channel.bulkDelete(filtered, true).then((messages) => {
        console.log(messages);
        Response.setDescription(`🧹 Cleared ${messages.size} from ${Target}.`);
        interaction.reply({ embeds: [Response] });
      });
    } else {
      await channel.bulkDelete(Amount, true).then((messages) => {
        Response.setDescription(
          `🧹 Cleared ${messages.size} from this channel.`
        );
        interaction.reply({ embeds: [Response] });
      });
    }
  },
};
cerulean spindle
#

The error as well

atomic citrus
#

thats the thing. theres no error

cerulean spindle
#

Nothing happens when you run it in a different channel?

jolly agate
cerulean spindle
jolly agate
#

I was thinking that the code returned somewhere (done that many times before without catching it)

atomic citrus
atomic citrus
#

i added the role the bot has to the permissions and gave it everything in both channels. but its only working in 1

cerulean spindle
jolly agate
#

do you have any error catching at all?

cerulean spindle
#

Could you show an example

atomic citrus
cerulean spindle
#

Also just deleting messages instead of deleting from target

#

Tell me if that works

atomic citrus
#

ok so it looks like its only working in 1 channel

#

from target

#

ok so regular clearing works. but when adding a target it doesnt

#

but without target looks like its messing up too

#

i did /clear 10
and it said it only cleared 1

#

but it works as intended in that 1 channel

cerulean spindle
#

Well does the target have messages in that channel

atomic citrus
#

yes

#

here let me try to record gif

cerulean spindle
#

Are the targets messages before you restarted the bot

cerulean spindle
#

Try sending messages while the bot is online then redo it

cerulean spindle
#

There is an error where the bot can not catch messages that was sent before the last restart

#

I don't think you can fix it

atomic citrus
#

its just a discord thing?

cerulean spindle
#

Yes

#

Same with message delete

#

You can't fetch the message after bot restarts

atomic citrus
#

alright. thanks