簡體   English   中英

為什么我的清除命令會刪除聊天中的所有消息而不是給定的數字?

[英]Why is my purge command deleting all the messages in the chat and not the given number?

我現在正在研究我的機器人一段時間,並且正在研究清除命令。 唯一的問題是機器人正在刪除聊天中的所有消息。 不是給定的數字。 這是代碼:

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)
        });

    
    }
} 

這是一個正常工作的!

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)
        });

    
    }
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM