I have a range of messages I want to fetch to be deleted. If I pass 3-5 for example and I have 5 messages * a b c d e*
I expect my command ^delmsg 3-5 to delete d and c.
I managed to get the ID (a snowflake) of d and tried to pass it to before, but it keeps fetching my command and e instead of d and c. I don't know what else I can do with this. Maybe I'm doing something wrong with promises that I'm not aware of.
Code:
const deleter = (message, range) => {
const range1 = range[0]; //indexes are already an array so we get the first index
const amnt = parseInt(range[1]) - parseInt(range[0]); //makes the str index ints
var msgs, nID;
message.channel.messages.fetch({
limit: range1,
}).then(a => {
msgs = Array.from(a);
nID = msgs[range1-1][0];
}).then(message.channel.messages.fetch({
limit: amnt,
before: nID,
}).then(b => {
//message.channel.bulkDelete(b);
}));
}
.then expects an uncalled function. You should use an arrow function there too, and it should work as intended
message.channel.messages.fetch({
limit: range1,
}).then(a => {
msgs = Array.from(a);
nID = msgs[range1-1][0];
}).then(() => message.channel.messages.fetch({ //notice it's an arrow function
limit: amnt,
before: nID,
})).then(b => {
message.channel.bulkDelete(b);
})
Also you should note the extra bracket at the end should go after the .then where you fetch the messages.