2

Today I wanted to try to create a discord bot with python. The problem i have is, that there is always an error message when I start the program:

Traceback (most recent call last):
  File "D:\...\Discord Bot\PythonGPU_Bot\bot.py", line 1, in <module>
    import discord
  File "C:\Users\...\Python\Python39\lib\discord\__init__.py", line 4, in <module>
    client = discord.Client()
AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)

Thats the Error message I always get. This is my script:

import discord
import asyncio

client = discord.Client()


@client.event
async def on_ready():
    print('Logged in as {}'.format(client.user.name))
    client.loop.create_task(status_task())


async def status_task():
    while True:
        await client.change_presence(activity=discord.Game('Hello <:'))
        await asyncio.sleep(1)
        await client.change_presence(activity=discord.Game('Hello c:'))
        await asyncio.sleep(1)


@client.event
async def on_message(message):
    if message.auther.bot:
        return
    if '.status' in message.content:
        await message.channel.send('SSSS')


client.run('ID')

I hope someone can help me out.

ReinerPing
  • 21
  • 2
  • Is this helping you? [Discord Bot Coding (AttributeError: partially initialized module..)](https://stackoverflow.com/questions/61430624/discord-bot-coding-attributeerror-partially-initialized-module) - Also: Have you updated your `discord.py` version? – Dominik May 26 '21 at 09:49
  • I already seen that post and it didnt help me out. I also updated the discord.py maybe i have to reinstall it, but I dont know how. – ReinerPing May 26 '21 at 10:18
  • Have you also tried to remove your client and replace it with: `client = commands.Bot(command_prefix="!")` and import `from discord.ext import commands`? *Note that this will support `commands` for your bot* – Dominik May 26 '21 at 10:23
  • Yes i tried it and the same issue appeard – ReinerPing May 26 '21 at 11:08
  • Have you tried to re-name your file/program? – Dominik May 26 '21 at 11:38
  • 1
    It is actually due to circular import. Rename your file! – Bhavyadeep Yadav May 26 '21 at 14:51

1 Answers1

0

The name of your file is discord.py, rename the file

rename it to bot.py or main.py or anything you like and your issue will be fixed

Why does it happen?

Since your file name is discord.py, it is actually importing that file and not the actual discord.py module you installed with pip.

Wasi Master
  • 1,112
  • 2
  • 11
  • 22