Python Discord bot failing to run: 'discord module not found' error despite pip installation

I’m having trouble with my Python Discord bot project. Every time I try to run the code, I get an error saying ‘discord module not found’. This is weird because I’m sure I installed discord.py using pip.

Here’s what my code looks like:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    print('Bot is online and ready!')

@bot.command()
async def greet(ctx):
    await ctx.send('Hello there!')

bot.run('YOUR_BOT_TOKEN_HERE')

I’ve double-checked my installation, but the error persists. Any ideas what might be causing this? Could it be a path issue or something else I’m overlooking? Thanks for any help!

hey man, have u tried using python3 instead of just python when running ur script? sometimes that fixes the import issue. also, make sure ur not using any weird characters in ur file name. that can mess things up too. gl with ur bot!

I’ve encountered this issue before, and it can be frustrating. Have you tried running ‘pip list’ in your terminal to confirm that discord.py is actually installed? Sometimes, it might be installed in a different Python environment than the one you’re using.

Another thing to check is your Python version. Discord.py requires Python 3.8 or higher. If you’re using an older version, that could explain the module not found error.

If those checks don’t solve it, try uninstalling and reinstalling discord.py. Use ‘pip uninstall discord.py’ followed by ‘pip install discord.py’. This has fixed similar issues for me in the past.

Lastly, ensure you’re running the script from the correct directory. If you’re in a different folder, Python might not find the installed packages.