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;
  }
Was this page helpful?