为什么我的清除命令删除聊天中的所有消息而不是给定的数字?

发布于 2025-02-03 04:17:28 字数 1204 浏览 3 评论 0原文

我现在正在研究机器人一段时间,并且正在处理清除命令。只有问题是该机器人正在删除聊天中的所有消息。不是给定的数字。这是代码:

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[1]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 

I am working on my bot for some time now, And I am working on a purge command. Only the problem is that the bot is deleting all the messages in the chat. Not the given number. Here is the code:

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[1]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2025-02-10 04:17:28

这是正常工作的!

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[0]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 

This is the one that works properly!

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[0]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文