Main.py Error after watching Tutorial

This is my code

and I get an error in the console that says

Traceback (most recent call last):
File “main.py”, line 4, in
client = discord.Client()
TypeError: initt() missing 1 required keyword-only argument:
‘intents’

also, does anyone know why I can’t create a .env file?

If you are referring to the tutorial at Python Discord Bot Tutorial – Code a Discord Bot And Host it for Free , I think it may be outdated. Both replit and discord.py appear to have changed in the last two years in ways that would be incompatible what is described there.

Currently, discord.py requires you to declare “intents” for your bot, as in this example:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if message.content == 'ping':
            await message.channel.send('pong')

intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run('token')

You can read more information here: discord.py · PyPI

As for .env on replit, you now create a virtual version using the GUI. On the sidebar, click on the padlock icon to create a “secret,” which is a key-value pair that will become a usable environment variable for your program.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.