Provide response if missing perms?

Is there a way to do if(this error message: DiscordAPIError[50013]: Missing Permissions) return message.reply('I am missing perms in X channel?'); since that error porivdes the channel ID and everything?
2 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Erin
ErinOP3y ago
That seems like a lot of work for something like this, no? I have checking perms in messageCreate... where would you suggest I check perms? So in my index.js where I load all the files and such? I don't understand. What file would you do it in? So, why wouldn't messageCreate work? I'm just trying to check basic read message history, send message, and view channel perms. Not anything advanced. Right now I check for that in my messageCreate.js with this:
// makes sure the bot can send messages in the channel this is ran in.
const channel = client.channels.cache.get(message.channel.id);
const botPermissionsIn = message.guild.members.me.permissionsIn(channel);
if(!botPermissionsIn.has(Discord.PermissionsBitField.Flags.SendMessages)) return message.author.send(`I can\'t send messages in that channel. I need to have the \`SEND MESSAGES\` permission for that channel. A mod or guild owner will need to update this. If you are seeing this in error, please run the \`${prefix}report\` command.`);

const botPerms = [Discord.PermissionsBitField.Flags.SendMessages, Discord.PermissionsBitField.Flags.ViewChannel, Discord.PermissionsBitField.Flags.ReadMessageHistory, ]
let v = 0;
for(const i of botPerms) {
if(!message.guild.members.me.permissionsIn(channel).has(i)) {
v++
}
if(v == botPerms.length) {
message.react('❌');
return message.author.send('I do not have the necessary permissions for this channel. I need \`Read Message History, View Channel, and Send Messages.\`');
}
}
// makes sure the bot can send messages in the channel this is ran in.
const channel = client.channels.cache.get(message.channel.id);
const botPermissionsIn = message.guild.members.me.permissionsIn(channel);
if(!botPermissionsIn.has(Discord.PermissionsBitField.Flags.SendMessages)) return message.author.send(`I can\'t send messages in that channel. I need to have the \`SEND MESSAGES\` permission for that channel. A mod or guild owner will need to update this. If you are seeing this in error, please run the \`${prefix}report\` command.`);

const botPerms = [Discord.PermissionsBitField.Flags.SendMessages, Discord.PermissionsBitField.Flags.ViewChannel, Discord.PermissionsBitField.Flags.ReadMessageHistory, ]
let v = 0;
for(const i of botPerms) {
if(!message.guild.members.me.permissionsIn(channel).has(i)) {
v++
}
if(v == botPerms.length) {
message.react('❌');
return message.author.send('I do not have the necessary permissions for this channel. I need \`Read Message History, View Channel, and Send Messages.\`');
}
}
but it doesn't seem to work. I only found out I was missing perms cause I checked the console. Does that only check in the channel that the message was sent in? Cause that may be the reason why. I may need to duplicate this for this command. Alright, ty.
Want results from more Discord servers?
Add your server