程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Discord.js 中的“超过 14 天的消息”问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Discord.js 中的“超过 14 天的消息”问题?

开发过程中遇到Discord.js 中的“超过 14 天的消息”问题的问题如何解决?下面主要结合日常开发的经验,给出你关于Discord.js 中的“超过 14 天的消息”问题的解决方法建议,希望对你解决Discord.js 中的“超过 14 天的消息”问题有所启发或帮助;

如果没有不超过 14 天的消息,我希望我的机器人返回一条消息,说“您不能删除 14 天之前的消息”。截至目前,它只返回“已删除的 ${messages.sizE} 条消息”,但实际上并未删除它们,因为它们都超过 14 天。

我的 purge.Js 文件:

const discord = require('discord.Js')
    
    module.exports = {
        name: 'purge',category: 'admin',description: 'Purges a specifIEd amount of messages from the chAnnel.',execute: async (message,args) => {
    
            let amount = args[0]
            
            if(!amount) amount = 100
    
            if(amount > 100) amount = 100
    
            if(amount < 1) return message.reply(`you need to @R_801_9421@e at least one message`)
    
            message.delete()
    
            await message.chAnnel.messages.fetch({limit: amount}).then(messages => {
                message.chAnnel.bulk@R_801_9421@e(messages,truE)
    
                message.chAnnel.send(`success! @R_801_9421@ed ${messages.sizE} messages.`)
                }
              );
    
          
              }
          }

解决方法

您以错误的方式使用了 .bulk@R_801_9421@e(...);bulk@R_801_9421@e 函数会为您提取消息,因此您不必这样做。
请参阅下面的示例以获取一些修复。

const Discord = require('discord.js'); // Define Discord
module.exports = {
    // Define command information
    name: 'purge',category: 'admin',description: 'Purges a specified amount of messages from the chAnnel.',execute: async (message,args) => { // The command function
        let amount = args[0]; // Get the amount of messages to @R_801_9421@e form the message
        if (typeof amount == 'number' && parseInt(amount > 100)) amount = 100; // Change amount if over maximum messages
        if (!typeof amount == 'number' || parseInt(amount < 1)) return message.reply('you must @R_801_9421@e at least one message'); // Display error message if they didn't provide an amount
    
        message.delete(); // @R_801_9421@e the users message
        message.chAnnel.bulk@R_801_9421@e(amount,truE).then(messages => { // Bulk @R_801_9421@e amount of messages
            message.chAnnel.send(`success! @R_801_9421@ed ${messages.sizE} messages.`); // Send success message
        }).catch(() => message.chAnnel.send('Please make sure the messages you are trying to @R_801_9421@e are under 14 days old.'); // CallBACk if messages are over 14 days old
    }
}

大佬总结

以上是大佬教程为你收集整理的Discord.js 中的“超过 14 天的消息”问题全部内容,希望文章能够帮你解决Discord.js 中的“超过 14 天的消息”问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。