Hey everyone! I’m trying to create a Discord bot using Python but I’m running into some issues. My code editor is showing 4 errors and I’m not sure why. I’ve already installed discord.py and I’m using Python 3.5.
Here are the errors I’m seeing:
No name 'exe' in module 'discord'
Undefined variable 'message'
Unable to import 'discord.exe.commands'
Undefined variable 'message'
I’ve double-checked my code but can’t figure out what’s wrong. Here’s a simplified version of what I’m working with:
import discord
from discord.bot.commands import Bot
from discord.ext import commands
client = commands.Bot(prefix='!')
@client.event
async def on_ready():
print('Bot is online')
@client.event
async def on_message(msg):
if msg.content == 'hi':
await msg.channel.send('Hello!')
client.run('BOT_TOKEN_HERE')
Can anyone spot what might be causing these errors? Any help would be great!
hey, i’ve had similar probs. try updating ur imports like this:
import discord
from discord.ext import commands
also, make sure ur using ‘message’ in the on_message function. oh and check ur python version - discord.py needs 3.8+ now. might wanna upgrade if ur still on 3.5. gl fixing it!
Based on the errors you’re seeing, it seems like there might be some issues with your import statements and variable naming. Try modifying your imports to just ‘import discord’ and ‘from discord.ext import commands’. Also, make sure you’re using ‘message’ consistently in your on_message event handler.
Another thing to consider is your Python version. Discord.py has evolved, and newer versions require Python 3.8+. If possible, I’d recommend upgrading your Python installation to at least 3.8 or higher.
Lastly, double-check that you’ve installed discord.py correctly. Sometimes, installation issues can cause unexpected errors. You might want to try reinstalling it using pip:
pip install -U discord.py
Hope this helps you resolve the issues!
I’ve encountered similar issues when setting up Discord bots. From what I can see, there are a few adjustments you can make in your code. First, update the import statements to:
import discord
from discord.ext import commands
Then remove the unnecessary import of Bot from discord.bot.commands. Also, change the bot instantiation from using the keyword prefix to command_prefix as follows:
client = commands.Bot(command_prefix='!')
Inside the on_message event, rename the parameter to message so that the reference inside the function is consistent:
async def on_message(message):
if message.content == 'hi':
await message.channel.send('Hello!')
Lastly, consider upgrading to at least Python 3.8 because discord.py versions 2.0 and above are not compatible with Python 3.5. These changes should help resolve the errors you’re encountering.