Search code examples
pythonherokudiscord.py

How to resolve the following error in discord.py: "TypeError __init__() missing 1 required keyword-only argument: 'intents'"


I'm using Heroku as my server host of my Discord.py bot, but i am having a problem. the problem is:

Traceback (most recent call last):
    File "test.py", line 4, in <module>
        client = discord.Client()
TypeError: __init__() missing 1 required keyword-only argument: 'intents'
Process exited with status 1

However here is my discord.py code

import discord
token = '(Obviously the token is here)'

bot = commands.Bot(command_prefix=prefix)

bot.run(token)

Solution

  • A little disclaimer: Join the discord.py server for more information, there are weekly updates since they are actively developing the library and changes can be breaking.

    Now every Client subclass needs the intents keysword as mentioned in the following picture:

    https://discord.com/invite/r3sSKJJ

    How to change the code:

    1. Head over to the Discord Developer Portal and click on your application
    2. Head over to Botand find Privileged Gateway Intents. Tick whatever you need
    3. In your code, you then need to import them:
    intents = discord.Intents.default() # or .all() if you ticked all, that is easier
    intents.members = True # If you ticked the SERVER MEMBERS INTENT
    
    bot = commands.Bot(command_prefix=".", intents=intents) # "Import" the intents
    

    This should resolve your error.