I have tried to add try and catch to my code so it does what I want it to do, however, I get this error:
TypeError: Cannot read property 'content' of undefined
This is my code:
if (!message.guild.me.hasPermission(`MANAGE_CHANNELS`)) return message.reply('I lack the required permissions to run this command. (Required Permissions: ``MANAGE_CHANNELS``)');
if(message.member.hasPermission("MANAGE_CHANNELS")){
const channel = message.channel;
const Discord = require("discord.js");
let role = message.mentions.roles.first() || message.guild.roles.cache.find(role => role.name === args.join(" "));
if(!role){
message.reply("please mention a role.")
} else{
message.reply('Are you sure you want to continue this command, it will disallow send permissions from the role you mentioned. Type ``yes`` to continue.')
let filter = msg => msg.author.id == message.author.id
message.channel.awaitMessages(filter, {max: 1, time: 20000}).then(collected => {
(Error line)> if (collected.first().content.toLowerCase() !== 'yes') return;
try {
const embed = new Discord.MessageEmbed()
.setTitle("Channel Locked")
.setColor("RED")
.setDescription(`Channel locked to the specified role`)
message.channel.updateOverwrite(role, {
SEND_MESSAGES: false
})
.then(channel => channel.send(embed))
.catch(console.error)
}
catch(error) {
message.reply("Command either timed out or there was an error.")
}
})
}
}
I'm not at all experienced with try and catch so I'm assuming I have done something wrong.
Thanks
question from:
https://stackoverflow.com/questions/65923314/typeerror-cannot-read-property-content-of-undefined-using-try-catch 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…