0

I am trying to write a Discord bot, but the bot won't start and raises this error:

AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)
Taku
  • 31,927
  • 11
  • 74
  • 85
baranuyukus
  • 49
  • 2
  • 8

3 Answers3

4

If the name of your file is discord.py try to change the name bot.py for example

  • 1
    Would care to explain why changing the file name works? Is this documented somewhere or based on your experience? – Arcanefoam Jul 08 '21 at 12:15
  • @Arcanefoam answering for the poster, the two parts "partially initialized module" and "most likely due to a circular import" are major hints in Python that a circular import has occurred. And changing the file name is the correct solution. – Taku Oct 24 '21 at 15:18
0

Your header (before you have any functions or method calls) should include the following items:

import discord
from discord.ext import commands

You also need to initialize your discord client. In this case, a client represents your script's connection to the discord server. If you don't initialize, none of your commands will work.

client = commands.Bot(command_prefix=".")

within the parenthesis, you can declare the prefix for your commands. Ex, .help vs !help.

Lastly, you need to connect your client to the server and run it in a continuous event loop. This should be at the end of your file.

client.run('your bot's token')
-3

Try to define your bot / client

var client = new Discord.Client();
Bin Floo
  • 9
  • 4