批量删除discord.js

时间:2020-06-21 16:24:30

标签: javascript node.js bots discord discord.js

我一直在构建我的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)
        }
         });

1 个答案:

答案 0 :(得分:1)

该错误是由您使用find()的方式引起的,您需要向其中传递一个函数

if (!message.member.roles.find((role) => role.name === "LOLI POLICE"))