【发布时间】:2023-03-08 15:38:01
【问题描述】:
我一直在构建我的 discord 机器人,但遇到了一些麻烦! 我的批量删除有效,但仅适用于您键入的 cmd,而不是我收到此错误
(node:146828) DeprecationWarning: Collection#find: pass a function instead
(node:146828) UnhandledPromiseRejectionWarning: ReferenceError: args is not defined
at purge (C:\Users\nevbw\Desktop\games\FBIBot\bot.js:29:13)
at Client.<anonymous> (C:\Users\nevbw\Desktop\games\FBIBot\bot.js:46:2)
at Client.emit (events.js:224:7)
at MessageCreateHandler.handle
client.on('message', message => {
if (message.content === 'L!delete') {
async function purge() {
message.delete();
if (!message.member.roles.find("name", "LOLI POLICE")) {
message.channel.send('You need the \`LOLI POLICE\` role to use this command.');
return;}
if (isNaN(args[0])) {
message.channel.send('Please use a number as your arguments. \n Usage: ' + `L!` + 'purge
<amount>');
return;
}
const fetched = await message.channel.fetchMessages({limit: args[0]})
console.log(fetched.size + ' messages found, deleting...');
// Deleting the messages
message.channel.bulkDelete(fetched)
.catch(error => message.channel.send(`Error: ${error}`));
it into the channel.
}
purge(); // Make sure this is inside the if(msg.startsWith)
}
});
【问题讨论】:
-
```是下面的代码是实际放入的cmd
-
一次删除的消息不能超过 100 条或 14 天以外的消息
-
@CedarBlocks 它甚至不能删除两条消息
标签: javascript node.js bots discord discord.js