message not being sent if missing perms

I have this code:
const botPermissionsIn = message.guild.members.me.permissionsIn(channel);
if(!botPermissionsIn.has(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 = [PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel, 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.\`');
}
}
const botPermissionsIn = message.guild.members.me.permissionsIn(channel);
if(!botPermissionsIn.has(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 = [PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel, 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.\`');
}
}
I'm not receiving any DMs for missing perms. Though the error shows in the console.
7 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.
Syjalo
Syjalo3y ago
So catch the error
Erin
ErinOP3y ago
How? Only way I know how to catch the error is to do a try/catch. Do I put this inside one of those?
Syjalo
Syjalo3y ago
Yes, or do
.send(...).catch(() => {
// code here
})
.send(...).catch(() => {
// code here
})
Erin
ErinOP3y ago
Nothing logged besides the missing perms error. Entire command: https://srcb.in/6LsyDiTtNx Logged on every .send as well as added a try/catch. with logging: https://srcb.in/RsNxwu83bI Still nothing but err DiscordAPIError[50013]: Missing Permissions logs. The bot has ZERO perms in this channel that I'm using for this test. The error appears exactly why I thought, because the bought doesn't have perms in the channel I'm trying to send the report embed to. This is expected behavior (for now). It can take the array? how? I do it this way cause I don't know how to do it any other way. Alright, is there a way to get (from the error message) exactly which perms are missing so I can put that in the message that is sent to the author? Alright, ty. Okay, now I'm having an issue with my bot sending the embed on usr.send even when it doesn't have perms in the channel for channel.send ? https://srcb.in/n2fqlU0uKD = whole code. I just want it to send the error message in DMs otherwise people may be confused if they receive both. Now the bot has perms in the channel but it still errors out saying it doesn't have perms. What?!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Erin
ErinOP3y ago
I did? that was the sourceb.in ... I don't understand. Sorry for the late replies, I didn't see these.
Want results from more Discord servers?
Add your server