【问题标题】:Cannot read property 'get' of undefined js无法读取未定义 js 的属性“get”
【发布时间】:2021-04-29 18:00:38
【问题描述】:

这是代码 -

module.exports = { 名称:'清除', 描述:“清除消息!”, 异步执行(消息,参数){ 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);
}

【问题讨论】:

  • 你需要显示更多的文件,比如你如何设置client.commands

标签: discord.js


【解决方案1】:

对不起,执行的命令是-

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

【讨论】:

    【解决方案2】:
    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]));
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 2018-05-08
      • 1970-01-01
      • 2017-04-28
      • 2020-09-04
      • 2021-12-01
      • 1970-01-01
      • 2021-12-31
      • 2021-12-17
      相关资源
      最近更新 更多