markdown\n# Help! My Discord bot isn't working\n\nI made a small Discord bot for my server but I'm truly stuck. When I run it with `python3.4 botscript.py`, I get an error that says:\n\n````\nNameError: name 'asyncio' is not defined\n````\n\nI tried installing asyncio, but the error still appears. Below is the updated code I wrote:\n\npython\nimport discord\nfrom discord.ext import commands\n\nnewBot = commands.Bot(prefix=‘##’, description=‘Bot description here’)\n\[email protected]\[email protected]\ndef on_bot_ready():\n print(‘Bot is online’)\n print(newBot.user.name)\n\n\nAm I missing a step or misusing asyncio somehow? Any suggestions would be really appreciated!\n
yo, ur issue is probs with python 3.4. its ancient bro! upgrade to 3.8+ and you’ll be golden. also, dont forget to import asyncio at the top of ur script. and use async/await instead of that old school coroutine stuff. should fix ur problem easy peasy. lmk if u need more help!
Hey there! I ran into a similar issue when I first started working with Discord bots. The problem is likely that you’re using Python 3.4, which doesn’t have built-in support for asyncio. I’d strongly recommend upgrading to at least Python 3.7 or higher.
Once you’ve upgraded, make sure to import asyncio at the top of your script:
import asyncio
import discord
from discord.ext import commands
Also, instead of using the @asyncio.coroutine decorator, you can use the async/await syntax, which is more modern and readable:
@newBot.event
async def on_ready():
print('Bot is online')
print(newBot.user.name)
These changes should resolve your NameError and get your bot up and running. Let me know if you need any more help!
I encountered a similar issue in my Discord bot development journey. The root cause is likely your Python version. Python 3.4 is quite outdated and lacks native asyncio support. I’d recommend upgrading to Python 3.8 or higher for optimal compatibility with modern Discord libraries. After upgrading, ensure you have the latest discord.py installed via pip. Then, modify your code slightly: Import asyncio at the top, use the async/await syntax instead of decorators, and rename ‘on_bot_ready’ to ‘on_ready’ as it’s the standard event name. With these adjustments, your bot should work smoothly. If you’re still facing issues, double-check your Discord developer portal settings and ensure your bot token is correct.