【问题标题】:Bulk delete discord.js批量删除 discord.js
【发布时间】: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


【解决方案1】:

这个错误是你使用find()的方式造成的,你需要传入一个函数

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

【讨论】:

  • 嗨,我试过了,但出现以下错误? C:\Users\nevbw\Desktop\games\FBIBot\bot.js:36 const fetched = await message.channel.fetchMessages({limit: args[0]}); // This grabs the last number(args) of messages in the channel. ^^^^^
  • 所以它说等待部分
  • 抱歉,回复晚了,但这是完整的错误,其余的只是机器人文件
  • 这不是错误,只是指向导致错误的行,请将完整错误编辑到您的问题中。
  • (node:623324) UnhandledPromiseRejectionWarning: ReferenceError: args is not defined
猜你喜欢
  • 2020-09-19
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-18
  • 2021-11-24
  • 2019-08-09
相关资源
最近更新 更多