discorddiscord.py

Discord bot intents declaration


I've seen on other posts that the bot events are easier than client ones. But I don't get if the intents declaration for client and bot is the same or not. Everytime i try to change the imports and the intents it doesn't work.

import os
from typing import Final
import discord
from discord import Client, Intents, Message
from discord.ext import commands
from responses import actions


# Load the token

TOKEN: Final[str] = os.environ['DISCORD_TOKEN']

# Bot setup

intents: Intents = Intents.default()

intents.message_content = True  # NOQA

client: Client = Client(intents=intents)


bot = commands.Bot(command_prefix='%', intents=intents)`

Solution

  • Bot is a subclass of client. They both do the same thing and derive from the same class but Bot sub-class has much more functionality than Client. Using them together is not recommended because the script will try to establish two seperate connections this way. Just use the bot class on its own. Taku has a great explanation for this:

    Bot is an extended version of Client (it's in a subclass relationship). Ie. it's an extension of Client with commands enabled, thus the name of the subdirectory ext/commands.

    You should read the original answer here: Taku's Answer