无法读取未定义 js 的属性“get”

时间:2021-01-25 22:09:16

标签: discord.js

这是代码 -

module.exports = { name: '清除', 描述:“清除消息!”, 异步执行(消息,参数){ if (!args[0]) return message.reply("请输入要清除的消息数量!");

    if(isNaN(args[0])) return message.reply("Please type a real number!");

    if(args[0] > 100) return message.reply("You can't remove more than 100 messages!");
    
    if(args[0] < 1) return message.reply("You have to delete at least one message!");

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

} }
错误 -

    if(command === 'clear'){
    client.commands.get('clear').execute(message, args);
}

2 个答案:

答案 0 :(得分:0)

抱歉命令执行的是 -

    if(command === 'clear'){
    client.commands.get('clear').execute(message, args);
}

和错误 -

C:\Users\heyno\Desktop\DiscordBot2\main.js:33
    client.commands.get('clear').execute(message, args);

答案 1 :(得分:0)

module.exports = { 
    name: 'clear', 
    description: "Clear messages!", 
    execute: async function(message, args) { // here were your issue
        if (!args[0]) 
            return message.reply("Please enter the amount of messages to clear!");

        if(isNaN(args[0])) 
            return message.reply("Please type a real number!");

        if(args[0] > 100) 
            return message.reply("You can't remove more than 100 messages!");

        if(args[0] < 1) 
            return message.reply("You have to delete at least one message!");

        message.channel.bulkDelete(parseInt(args[0]));
    } 
}