how can i check the channel permissions to send message
In my case i am in an event called userUpdate.js where my code is something like
module.exports = async (client,oldUser, newUser) => {
if (newUser.bot) return;
if(oldUser.username === newUser.username) return ;
var log = client.guilds.channels.find(ch => ch.name.includes('member-log'));
if (log != null)
var sEmbed = new Discord.RichEmbed()
.setColor("RANDOM")
.setTimestamp()
.setDescription(`**OLD-USER** <@${oldUser.username}> **NEW-USER**\n<@${newUser.id}>`)
log.send(sEmbed);
}
but it doesn't have message parameter like in message event so how can i check bots permission
if (!message.channel.permissionsFor(client.user).has("SEND_MESSAGES")) return;
so how shall i put this in the userUpdate.js event file ?
I see you have the variable
log
which is the channel you want to send the message to. Just use the same snippet as above, but replacemessage.channel
withlog
.Also: Your error handling is pretty bad in the script above and may could make more errors instead of preventing them. Probably try just returning if log is null. You could replace the line
if (log != null)
withif (!log) return;