'My discord code is not working! It only shows error when i run the program

Here is the code:

import discord
from discord.ext import commands

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

@bot.command()
async def sayhi(ctx, name):
    await ctx.send(f"Hi {name}!")


bot.run("TOKEN")

And here is the error what im getting:

ModuleNotFoundError: No module named 'discord.ext'; 'discord' is not a package

But i all ready did pip install discord command in cmd!



Solution 1:[1]

It seems to me, that you named your file were you are working in discord.py. This Filename is already reserved for the package you are importing. If you now name your working file to the name of a file, which is reserved by a package, it will try to import iteself which obviusly throw you a errorcode. a simple solution is to rename the file to something else than discord.py

Solution 2:[2]

try this

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

@bot.command()
async def sayhi(ctx, member):
    await ctx.send(f"Hi {member.mention}!")


bot.run("TOKEN")

make sure you do pip install discord.py into you console

Solution 3:[3]

You use the grep program.

grep "no user exists" FILE1 FILE2 FILE3 ...

That's not a "wildcard string". That's just a string to search for, and grep will show you ever line that matches in every file.

If all you want is a list of files, use the -l option.

grep -l "no user exists" FILE1 FILE2 FILE3 ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Toastlover
Solution 2
Solution 3 Andy Lester