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?