Why dose line 12 not work? can't figure out why

Question:
why dose line 12 not correct? i am a beginner using a tutorial trying to learn.
Repl link:
https://replit.com/@SadeghiArmeen/NaiveTiredDiskdrive
Running the code in my project results in the error:

Traceback (most recent call last):
  File "/home/runner/NaiveTiredDiskdrive/.pythonlibs/lib/python3.10/site-packages/discord/http.py", line 803, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/home/runner/NaiveTiredDiskdrive/.pythonlibs/lib/python3.10/site-packages/discord/http.py", line 745, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized

i actually mean

import os
import random
import discord
my_secret = os.environ['TOKEN']

intents = discord.Intents.default()
intents.typing = False
intents.presences = False
client = discord.Client(intents=intents)


client.run(my_secret)
@client.event
async def on_ready():
    print(f'{client.user.name} has connected to Discord!')

@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(
        f'Hi {member.name}, welcome to my Discord server!'
    )

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    brooklyn_99_quotes = [
        'I\'m the human form of the 💯 emoji.',
        'Bingpot!',
        (
            'Cool. Cool cool cool cool cool cool cool, '
            'no doubt no doubt no doubt no doubt.'
        ),
    ]

    if message.content == '99!':
        response = random.choice(brooklyn_99_quotes)
        await message.channel.send(response)
    elif message.content == 'raise-exception':
        raise discord.DiscordException

This usually happens when you are using the wrong token.
Try to generate a new one and change the old token.

Also, be sure that all permissions are enabled in your Discord Developer Portal.

1 Like

Hi,
It seems that you have done the client.run(mysecret) before all your code is over.
Make sure to put this line on the bottom (last line) of your code.