2
votes

I recently started to learn python by making bots for Discord. I can't run 'from discord.ext import commands'. Can you guys help, please? I succeeded in importing discord.py from cmd, but I don't know how to import discord.ext. I don't know if I'm importing discord.ext

Here is the Code: (This code is not all of the code.)

    import discord
    from discord.ext.commands import Bot
    from discord.ext import commands
    import os
    import random
    import openpyxl
    from openpyxl import load_workbook
    import time
    import sys
    import asyncio
    import datetime

    TOKEN = os.environ['BOT_TOKEN']

    @client.event

    async def on_message(message):
        if message.author.bot:
            return None

        if message.content.startswith("!명령어"):
            command_list = ["!강화 !도박", "!순위 !내순위" ,"!내레벨", "!노래","!행운의숫자", "!개발자명령어"]
            command_msg_list = ["강화를 진행합니다.", "강화 순위를 표시합니다.","내 강화 레벨을 표시합니다.", "★★★추천 노래를 표시합니다.★★★","1부터 99까지 숫자 중 행운의 숫자를 골라줍니다.","개발자를 위한 명령어들을 표시합니다."]
            embed = discord.Embed(title="명령어",color=0x62c1cc)
            for i in range(len(command_list)):
                embed.add_field(name=command_list[i], value=command_msg_list[i], inline=False)
            await message.channel.send(embed=embed)

        if message.content.startswith("!개발자명령어"):
            command_list = ["!디렉토리표시"]
            command_msg_list = ["봇이 실행되고 있는 디렉토리를 표시합니다."]
            embed = discord.Embed(title="개발자 명령어",color=0x62c1cc)
            for i in range(len(command_list)):
                embed.add_field(name=command_list[i], value=command_msg_list[i], inline=False)
            await message.channel.send(embed=embed)

1
Please run python -m discord -v and post the output. - Łukasz Kwieciński
Should I run it in cmd? I tried, but it only printed 'Python'. ``` Microsoft Windows [Version 10.0.18363.1256] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\wnrdm>python -m discord -v Python C:\Users\wnrdm>py python -m discord -v C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe: can't open file 'python': [Errno 2] No such file or directory ``` - white201
Make sure you are running the latest version of discord.py: pip install --upgrade discord.py - idontknow

1 Answers

1
votes

Put the from commands at the bottom and the Import commands at the top and see if it works.

Also, if pip install (add-on) doesn't work try:

py -m pip (pip command)