Bot permission in channel

I'm trying to get my bot to check if it has permissions to send a message in a channel. It will mainly be for text channels but also in forum posts and voice channels. Not sure what I'm doing wrong. I'm getting the IDs for the guild and channel from a database.
const guild = client.guilds.cache.get(result[i].Guild);
...
const channel = guild.channels.fetch(result[i].ChannelID);
const channel = guild.channels.fetch(result[i].ChannelID);
if (channel) {
// Check permissions
if (!channel.permissionsFor(guild.members.me).has(PermissionFlagsBits.SendMessages)) {
logger.error(`Unable to post Queued Message ${result[i].QueuedMsgID} - Bot does not have permission to send messages in ${channel.name} in ${guild.name}`);
return;
}
const guild = client.guilds.cache.get(result[i].Guild);
...
const channel = guild.channels.fetch(result[i].ChannelID);
const channel = guild.channels.fetch(result[i].ChannelID);
if (channel) {
// Check permissions
if (!channel.permissionsFor(guild.members.me).has(PermissionFlagsBits.SendMessages)) {
logger.error(`Unable to post Queued Message ${result[i].QueuedMsgID} - Bot does not have permission to send messages in ${channel.name} in ${guild.name}`);
return;
}
3 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
sproj003 ♿
sproj003 ♿OP8mo ago
I get this error TypeError: channel.permissionsFor is not a function [email protected] npm v18.18.2
Gabriel
Gabriel8mo ago
Hey! Fetch functions are promises so you should wait for a response:
const channel = await guild.channels.fetch(result[i].ChannelID);
const channel = await guild.channels.fetch(result[i].ChannelID);
Want results from more Discord servers?
Add your server