我有一系列要删除的消息。例如,如果我通过3-5,并且我有5条消息*a,b,c,d,e*
我希望命令^delmsg 3-5删除d和c。
我设法获得了d的ID (一片雪花),并试图将它传递给before,但是它一直在获取我的命令和e,而不是d和c。我不知道我还能用它做什么。也许我做错了我不知道的承诺。
代码:
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);
}));
}发布于 2021-10-21 18:24:45
.then需要一个未调用的函数。您也应该在那里使用箭头函数,并且它应该按预期工作。
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);
})此外,您还应该注意,末尾的额外括号应该在获取消息的.then之后。
https://stackoverflow.com/questions/69666873
复制相似问题