pythonpython-3.xpython-asynciodiscord.py

NameError: name 'asyncio' is not defined; In running discord bot


I'm working on a small discord bot for a server I made, however I've run into a problem. Whenever I try to run the bot (using python3.4 lilac.py), I get the following error:

Traceback (most recent call last):
  File "lilac.py", line 7, in <module>
    @asyncio.coroutine
NameError: name 'asyncio' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0xb61ad470>

I tried to install it via python3.4 -m pip install asyncio, and even though it said the install was successful, I still get the error. This is the full code:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='&&', description="Description     here")

@bot.event
@asyncio.coroutine
def on_ready():
    print('Logged in as')
    print(bot.user.name)

Is there anything I didn't install correctly? Am I calling asyncio incorrectly? Any help is appreciated, I can give more info if needed.


Solution

  • You forgot to import asyncio in your code. just add the following into the first line of your code

    import asyncio