简体   繁体   English

Discord.JS bulkDelete 14 天错误预防?

[英]Discord.JS bulkDelete 14 day Error Preventation?

How would I stop a purge command using bulkDelete in Discord.JS from sending an error if it is over 14 days old?如果使用bulkDelete中的 bulkDelete 的清除命令超过 14 天,我将如何阻止它发送错误? As it spams the console and it's pretty annoying.因为它向控制台发送垃圾邮件,这很烦人。 I have already tried putting it in a try/catch block but it didn't help.我已经尝试将它放在 try/catch 块中,但没有帮助。

Any help will be appreciated:)任何帮助将不胜感激:)

Code:代码:

 if (Number.isNaN(+content)){;
            message.channel.send('Please enter a valid numerical digit.')
        } else{
            if(message.member.hasPermission('MANAGE_MESSAGES')){
                try{
                    if(content > 100){
                        message.reply("Unable to purge. Limit is 100.")
                    } else{
                        message.channel.bulkDelete(content)
                        
                        
                        message.reply(`successfully purged ${content} messages.`)
                        .then(msg => {
                        msg.delete({ timeout: 5000 })
                        .catch(console.error)
                        })
                    }
                }catch(error){
                    message.reply(`There was an error.`)
                    console.log(error)
                }
            } else{
                message.reply("You lack the required permissions to do that. (Required Permissions: ``MANAGE_MESSAGES``)")
            }
        }

.bulkDelete() accepts a second argument (a boolean) which if set to true , filters messages to remove those older than two weeks. .bulkDelete()接受第二个参数(布尔值),如果设置为true ,则过滤消息以删除超过两周的消息。 The default value is set to false .默认值设置为false

The following should work as expected:以下应该按预期工作:

message.channel.bulkDelete(content, true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM