0

I want to make a discord bot then it keep showing cant find then Client in discord package.Did I install wrong discord package?

# TOKEN and CHANNEL redacted
import discord

client = discord.Client()


@client.event
async def msg():
    general = client.get_channel(CHANNEL)
    await general.send('HELLO')


client.run(TOKEN)

Runtime error:

Traceback (most recent call last):
  File "C:/Users/user/Desktop/dis.py", line 1, in <module>
    import discord
  File "C:\Users\user\Desktop\venv\lib\site-packages\discord\__init__.py", line 25, in <module>
    from .client import Client
  File "C:\Users\user\Desktop\venv\lib\site-packages\discord\client.py", line 27, in <module>
    import asyncio
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
    from .base_events import *
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 39, in <module>
    from . import coroutines
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\coroutines.py", line 5, in <module>
    import inspect
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\inspect.py", line 35, in <module>
    import dis
  File "C:\Users\user\Desktop\dis.py", line 3, in <module>
    client = discord.Client()
AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)

Process finished with exit code 1
chris
  • 4,840
  • 5
  • 35
  • 66

9 Answers9

1

First of all, you leaked the discord token for your bot so you should regenerate it.

This is what I do when making a bot,

import discord
from discord.ext import commands

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

@client.event
async def hi(ctx):
    await ctx.send("HELLO")

This should work

0

Try to use

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

Instead of

client = discord.Client()

Then you can respond to bot commands like this:

    @client.event
    async def ping(ctx):
        await ctx.send("Pong")

It always works for me when creating a Discord bot with commands. You can also check out this article, I'm sure that it will help you a lot. https://betterprogramming.pub/how-to-make-discord-bot-commands-in-python-2cae39cbfd55

Peter Till
  • 91
  • 6
-1

A: DELETE THIS RIGHT NOW YOU HAVE LEAKED YOUR BOT TOKEN OH GOD OH S***

B: most likely due to a circular import

make sure you arent importing dicord a second time in any of your other imports (if present)

and make sure your file is not named discord.py

abby luna
  • 9
  • 1
-1

Ok, so try this:

import discord
from discord.ext import commands

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

@client.event
async def on_ready():
    general = client.get_channel(CHANNEL)
    await general.send('HELLO')

Tell me if anything goes wrong. However, I don't know if your code under @client.event will work. I didn't test that out yet. Hope this helped :) Again : tell me if anything goes wrong.

Shlok Sharma
  • 23
  • 1
  • 4
-1

First off you need to add your imports!

import discord
from discord.ext import commands

Second you need to add your prefix

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

Fix your command

@client.command()
async def msg(ctx):
    await ctx.send("HELLO")

then add your token of course! Full code:

import discord
from discord.ext import commands

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

@client.event
async def hi(ctx):
    await ctx.send("HELLO")

I made your on_ready command a command because if you have the bot in multiple servers you will get banned from discord api in an instant!

PandaDev
  • 1
  • 2
-1

Assuming you want to message a user through a direct message this simple code is your answer. you would message someone by typing --msg @(Username) (Message)

import discord
from discord.ext import commands

@client.command(pass_context=True, aliases=["dm", "message", "directmessage"])
@commands.has_role("pog")
async def msg(ctx, member: discord.Member, *, message):
    em = discord.Embed(title=f"Incoming Message from {ctx.author}", description=f"{str(message)}", color=discord.Colour.blue())
    await member.send(embed=em)

client.run('TOKEN')

P.S I added a embed because it looks cool but you can remove that.

SecretLloyd
  • 109
  • 1
  • 13
-1

discord.Client() isn't a function. Define the client like this:

import discord
from discord.ext import commands

You need the intents to access some functions like: on_member_join and on_member_remove

intents = discord.Intents.all()    

client = commands.Bot(command_prefix="!", intents=intents, owner_id=putyouridhere)

@client.event
async def on_ready():
    print("Bot is ready.")
    general = client.get_channel(CHANNEL)
    await general.send('HELLO')

client.run("TOKEN")
Malware
  • 89
  • 4
-1

First, install it.

pip install discord

and try this simple code

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='Your_Prefix')

@client.event
async def on_ready():
    print("Bot now is online!!!")

client.run("Bot token")
Ali FGT
  • 55
  • 8
-2

The problem here seems to be that you're using the wrong package to get the client.

To fix this do

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='prefix you want')

I hope this may help you

jjoy
  • 162
  • 1
  • 10