Getting 403 Forbidden error with Discord bot despite setting permissions

Discord Bot Permission Issues

I’m building a Discord bot that searches for book information and returns data to users. The bot works fine when I give it administrator privileges, but I don’t want to do that for security reasons.

The problem is I keep getting a 403 Forbidden error (Missing Permissions) even though I think I’ve set the right permissions. Here’s my code:

import discord
import asyncio
from book_api import fetch_book_data, get_book_details
from config import load_config

bot_intents = discord.Intents.default()
bot_intents.message_content = True
bot_client = discord.Client(intents=bot_intents)

load_config()

@bot_client.event
async def on_ready():
    print(f"Bot is online as {bot_client.user}")

@bot_client.event
async def on_message(msg):
    if msg.author == bot_client.user:
        return

    if msg.content.startswith("/find"):
        user_query = msg.content
        search_term = user_query.split(" ", 1)[1]
        print(f"Book search: {search_term}")
        try:
            await msg.channel.send(fetch_book_data(search_term))
        except Exception as error:
            await msg.channel.send(f"Sorry, no books found for {search_term}")

    if msg.content.startswith("/info"):
        user_query = msg.content
        book_id = user_query.split(" ", 1)[1]
        print(f"Book info: {book_id}")
        
        try:
            await msg.channel.send(get_book_details(book_id))
        except Exception as error:
            await msg.channel.send("Unable to get book information right now")
            print(str(error))

bot_client.run(TOKEN)

Error I’m getting:

discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

I’ve tried enabling different permissions one by one but can’t figure out which specific ones are needed. What permissions should I enable for a bot that just needs to read messages and send responses?

check if your bot has ‘view channel’ permission - I hit this same issue because my bot couldn’t see the channel despite having send message perms. also position the bot role high enough in your server’s hierarchy since lower roles get blocked by channel overwrites.

I encountered a similar issue with a Discord bot I developed. The 403 Forbidden error usually indicates that the bot lacks necessary permissions in the channel, rather than problems with your code. Make sure to check the channel settings individually since they can override your bot’s permissions set at the server level. Specifically, ensure that it has permissions to “Send Messages” and “Read Message History”. Additionally, review any overwrites on the channel that could prevent bots from operating correctly. Your code appears solid, so it’s most likely a permissions issue.

Check your bot’s permissions in the Discord Developer Portal when generating the invite link. The scopes and permissions you pick there control what your bot can do after joining a server. For a basic messaging bot, you’ll need the ‘bot’ scope plus ‘Send Messages’, ‘Read Messages’, and ‘Use Slash Commands’ permissions. If your bot was invited without the right permissions, generate a new invite URL with correct permissions and have a server admin re-authorize it. Also check if specific channels have permission overwrites blocking bot access - even when server-wide permissions look fine.