简体   繁体   English

discord.js 无法读取未定义的属性“第一个”

[英]discord.js Cannot read property 'first' of undefined

    name: 'purge',
    description: "Purge messages from the chat.",
    execute(message, args, Discord){
        const Error = new Discord.MessageEmbed()
        .setTitle("Correct Usage")
        .setColor('#4e5d94')
        .setDescription("```>purge [integer] [<channel>]```");
        if(message.member.permissions.has("MANAGE_MESSAGES")){
            if(!args[0]) return message.reply(Error);
            if(isNaN(args[0])) return message.reply(Error);
            if(args[0] > 150) return message.reply(Error.setDescription("```Integer should be smaller than 150```".setTitle("Error")));
            if(args[0] <= 0) return message.reply(Error.setDescription("```Integer should be bigger than 0```").setTitle("Error"));
            if(args[1]){
                try{
                    let channel = message.mentions.channel.first();
                    channel.bulkDelete(args[0]);
                    message.channel.send(Error.setTitle("Cleared").setDescription("```Successfully cleared " + args[0] + " messages from " + channel + "```"))
                }catch(e){
                    console.log(e)
                    message.reply(Error.setTitle("Error").setDescription("```Client has run into a problem , please contact the developers.```"))
                }
            } else{
                message.channel.bulkDelete(args[0]);
                message.channel.send(Error.setTitle("Cleared").setDescription("```Successfully cleared " + args[0] + " messages```"))
            }
        } else{
            message.reply(Error.setTitle("Permission").setDescription("```Insufficient permission.```"))
        }
    }
}

the error is : Cannot read property 'first' of undefined it used to work but for some reason it just wont no , can anyone help me?错误是:无法读取未定义的“第一”属性,它曾经可以工作,但由于某种原因它不会,有人可以帮助我吗? i have been trying to fix this thing for a bit now我一直在尝试解决这个问题

It is a simple case of Typo my friend.这是我朋友的一个简单的错字案例。

It should be它应该是

                    let channel = message.mentions.channels.first();

Since message.mentions.channels is the property which you are trying to access.由于 message.mentions.channels 是您尝试访问的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:无法读取未定义 Discord.js node.js v12.16.3 的属性“第一个” - TypeError: Cannot read property 'first' of undefined Discord.js node.js v12.16.3 如果没有用户对第一反应做出反应,则 Discord.js 反应收集器将失败。 无法读取未定义的属性“计数” - Discord.js Reaction collector failing if no user reacts with first reaction. Cannot read property 'count' of undefined 无法读取 Discord.js 中未定义的属性“join” - Cannot read property 'join' of undefined in Discord.js Discord.js 无法读取未定义的属性“推送” - Discord.js Cannot read property 'push' of undefined 类型错误:无法读取未定义的 discord.js 的属性“用户名” - TypeError: Cannot read property 'username' of undefined discord.js 无法读取 discord.js 中未定义的属性“api” - Cannot read property 'api' of undefined in discord.js Discord.js | 类型错误:无法读取未定义的属性“声音” - Discord.js | TypeError: Cannot read property 'voice' of undefined 无法读取模块 discord.js 中未定义的属性发送 - Cannot read property send of undefined in module discord.js TypeError:无法读取未定义的discord.js的属性“ add” - TypeError: Cannot read property 'add' of undefined discord.js Discord.js | 无法读取未定义的属性“setParent” | 类别创建 - Discord.js | Cannot read property 'setParent' of undefined | category create
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM