Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

javascript - TypeError: Cannot read property 'bulkDelete' of undefined

I don't know what the problem is, I always get an error message when I execute the command: TypeError: Cannot read property 'bulkDelete' of undefined

My Code:

module.exports = {
    name: 'clear',
    async execute(message, args) {
       
        if (!args[0]) return message.channel.send("-")
        if (isNaN(args[0])) return message.channel.send("-")

        if (args[0] > 100) return message.channel.send("-")
        if (args[0] < 1) return message.channel.send

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

        });

    }
}
question from:https://stackoverflow.com/questions/65944464/typeerror-cannot-read-property-bulkdelete-of-undefined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Regardless of what bulkDelete is try to check if it exists like:

if (message?.channel?.bulkDelete) {
  message.channel.bulkDelete();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...