Check if my bot has perms in a channel?

Isn't this the correct way to do it?
// 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.me.permissionsIn(channel);
if(botPermissionsIn !== Discord.PermissionsBitField.Flags.SendMessages) return message.author.send('I can\'t send messages in that channel.');

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.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.me.permissionsIn(channel);
if(botPermissionsIn !== Discord.PermissionsBitField.Flags.SendMessages) return message.author.send('I can\'t send messages in that channel.');

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.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 am on v14.3.0 though that was not an option for the tags.
12 Replies
d.js docs
d.js docs2y 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.
Idris
Idris2y ago
- guild.me
+ guild.members.me
- guild.me
+ guild.members.me
Erin
Erin2y ago
Okay, no error but it is sending me a message by default saying that it can't send messages in the channel I ran the command in when before I added this code, it could just fine. So I know it can but it just stops at this...
if(botPermissionsIn !== Discord.PermissionsBitField.Flags.SendMessages) return message.author.send('I can\'t send messages in that channel.');
if(botPermissionsIn !== Discord.PermissionsBitField.Flags.SendMessages) return message.author.send('I can\'t send messages in that channel.');
Idris
Idris2y ago
you’re mixing v13 and v14 classes run npm ls discord.js and show the output
Erin
Erin2y ago
I literally just updated to v14.3.0 Ran uninstall and install @latest
Idris
Idris2y ago
run npm ls discord.js and show the output
Erin
Erin2y ago
Like I said, just updated...
# npm ls discord.js
sakura-moon@ /root/sakura-moon
`-- discord.js@14.3.0
# npm ls discord.js
sakura-moon@ /root/sakura-moon
`-- discord.js@14.3.0
# node -v
v16.15.0
# node -v
v16.15.0
Idris
Idris2y ago
^ ^
Erin
Erin2y ago
I updated them all...
// 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 !== 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 !== 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.\`');
}
}
Still stops here:
if(botPermissionsIn !== 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.`);
if(botPermissionsIn !== 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.`);
Idris
Idris2y ago
if (botPermissionsIn.has(Discord.PermissionsFlagsBits.SendMessages))
Erin
Erin2y ago
Same thing. Figured it out.
Idris
Idris2y ago
yeah forgot the negation ._.