0

I'm trying to run a discord bot in Spyder (anaconda 3 version), but it keeps giving me the Runtime error, similar to the one in these two questions:

I have installed nest_asyncio and aiohttps As for installing Discord.py Rewrite, I'm not 100% sure whether I have it or not. In conda, I installed discord.py by typing conda install -c conda-forge discord.py I am using Windows 10.

In the second question, they said they tried running their code in the command prompt, so I tried that and got this:

  client.run(TOKEN)
File "C:\Users\swanl\anaconda3\lib\site-packages\discord\client.py", line 723, in run
  return future.result()
File "C:\Users\swanl\anaconda3\lib\asyncio\futures.py", line 178, in result
  raise self._exception
File "C:\Users\swanl\anaconda3\lib\asyncio\tasks.py", line 280, in __step
  result = coro.send(None)
File "C:\Users\swanl\anaconda3\lib\site-packages\discord\client.py", line 702, in runner
  await self.start(*args, **kwargs)
File "C:\Users\swanl\anaconda3\lib\site-packages\discord\client.py", line 665, in start
  await self.login(*args, bot=bot)
File "C:\Users\swanl\anaconda3\lib\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'

Here's my code:

import os
import discord

import nest_asyncio
nest_asyncio.apply()

from discord.ext import commands
from discord.utils import get

from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

client = discord.Client()

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

client.run(TOKEN)

Thanks!

fluffs77
  • 3
  • 3
  • 1
    `os.getenv` returns `None` if the key doesn't exist, have you made sure `TOKEN` was your actual token and not a NoneType? – MrSpaar Aug 04 '21 at 07:58
  • Thanks, I figured out a way here: https://stackoverflow.com/a/65685817/16411361 I ran my environment variable code in startup. – fluffs77 Aug 05 '21 at 17:56

0 Answers0