Discord bot coding - repl.it - python

when i run this code

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}  '.format(client))

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

  if message.content.startswith('mango hello'):
    await message.channel.send('Hello!')

client.run(os.getenv(''))

i get this error message

Traceback (most recent call last):

  File "main.py", line 18, in <module>
    client.run(os.getenv('ODQ2NzU0OTgzMzc3MzcxMjI4.YK0IBw.BFsCEE_RY22U9LdTDo1Nwrgh2kY'))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
    return future.result()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'

how do i fix this?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

HI @KingKayhan !

It shouldn’t be an empty string here

You should use the Token

client.run(os.getenv('TOKEN'))

Also you will need to make sure to create the env file properly

You can’t do it the way the video does because replit changed the way you create env files.

You have to use the secrets tab to enter your token.

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