#channel.bulkDelete not working in some channels
1 messages · Page 1 of 1 (latest)
Show the code, it may be permission error
@jolly agate you don't need to create a thread for every question
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] });
});
}
},
};
The error as well
thats the thing. theres no error
Nothing happens when you run it in a different channel?
I know but it helps to keep #djs-help-v14 organized and so I can help individual members
Doesn't at all it's pretty annoying to join a thread every time to help somebody
I was thinking that the code returned somewhere (done that many times before without catching it)
it runs and just says Cleared 0 messages from user
Sorry
i added the role the bot has to the permissions and gave it everything in both channels. but its only working in 1
It's not this
So it works in a single channel but does not in others?
do you have any error catching at all?
Could you show an example
i havent tried in others, just those 2. let me try another
Also just deleting messages instead of deleting from target
Tell me if that works
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
Well does the target have messages in that channel
Are the targets messages before you restarted the bot
yes
Try sending messages while the bot is online then redo it
that works
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
ya that looks like the issue
alright. thanks