简体   繁体   English

我的清除命令 (Discord.js) 有问题

[英]I'm having an issue with my Purge command (Discord.js)

When I use the command, if there are messages older than 14 days and there are a few messages not older than 14 days, I'm able to delete those messages not older than 14 days, but still get the 14 days error.当我使用该命令时,如果有超过 14 天的消息并且有一些消息不超过 14 天,我可以删除不超过 14 天的那些消息,但仍然会收到 14 天错误。 I want it to return the error only if there are 0 messages not older than 14 days.我希望它仅在有 0 条不超过 14 天的消息时才返回错误。 Please help.请帮忙。

My code:我的代码:

File name: purge.js文件名:purge.js

module.exports = {
    
        name: "purge",
        aliases: ['clear'],
        category: "moderation",
        permissions: "MANAGE_MESSAGES",
        description: "Deletes messages from a channel.",
        usage: "purge [amount of messages] [ignore pinned messages]",
  
    execute: async (message, args) => {
        if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You don't have enough perms! You require: [MANAGE_MESSAGES]")

        message.delete()
        if (!args[0]) {
            message.channel.bulkDelete(100)
          .then().catch(e => {
            message.channel.send(e.message)
              })
            .then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
            return
          
        }
        else if (args[0] === "true") {
          
        const fetched = await message.channel.messages.fetch({ limit: 100 });
        const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);

        await message.channel.bulkDelete(notPinned)
            .then().catch(e => {
            message.channel.send(e.message)
              })
            .then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages.**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
            return
        
      }

        
            

        else if (parseInt(args[0]) > 100) {
            return message.channel.send("**Please Supply A Number Less Than 100!**");
        }

        else if (parseInt(args[0]) < 1) {
            return message.channel.send("**Please Supply A Number More Than 1!**");
        }
        if (args[1] === "true") {
          
          const fetched = await message.channel.messages.fetch({ limit: args[0] });
          const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);

          await message.channel.bulkDelete(notPinned)
            .then().catch(e => {
            message.channel.send(e.message)
              })
            .then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
            return
                  
        }
        else {
            message.channel.bulkDelete(args[0])
            .then().catch(e => {
            message.channel.send(e.message)
            })
            .then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
            return
        }
        
    },
};

bulkDelete can take a 2nd argument called filterOld. bulkDelete可以采用名为 filterOld 的第二个参数。 As the name suggests, that makes discord.js ignore all messages older than 14 days.顾名思义,这使得 discord.js 忽略所有超过 14 天的消息。

Example:例子:

message.channel.bulkDelete(notPinned, true)

message.channel.bulkDelete(args[0], true)

使用message.channel.bulkDelete(<amount>, true)

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

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