简体   繁体   中英

Python problem to install discord.py using pip

I tried installing the discord.py module according to the instructionsbut my code don't execute.

Traceback (most recent call last):
  File "c:/Users/Cyril/Desktop/@Dev/pyDiscord/main.py", line 1, in <module>
    import discord
ModuleNotFoundError: No module named 'discord'

I tried to install all the requirements, and they are all installed. When i try all the command like:

pip install discord.py

or

python -m pip install discord.py

I get various message, but at the start of all the output are:

Requirement already satisfied:

My IDE is Visual Studio Code. pip is on the last version (20.1.1). My Python version is 3.8.3.

Open cmd and run this command:

py -3 -m pip install -U discord.py

The message Collecting discord.py should appear if discord module is not (properly) installed on your machine, otherwise, try running cmd as an administrator and do the same installation process, if the error still exists, try reinstalling python

Run this program to check whether the error is fixed or not:

import discord
from discord.ext import commands

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

@bot.command()
async def ping(ctx):
    await ctx.send('pong')
try:
    bot.run('token')
except discord.errors.LoginFailure: 
    print("invalid token")
#remove the exception block if you have a valid token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM