简体   繁体   English

Discord.py 错误:没有命名客户端的属性

[英]Discord.py error: no attrbute named client

I am new to coding and I made a discord bot by copy-pasting the code on freecodecamp.我是编码新手,我通过在 freecodecamp 上复制粘贴代码制作了 discord 机器人。 When I ran the program, it gave me this message:当我运行程序时,它给了我这样的信息:

Traceback (most recent call last): File "C:\Users\polly\Desktop\HACK\Discord Bot\Python\bot.py", line 4, in client = discord.Client() AttributeError: module 'discord' has no attribute 'Client'回溯(最近一次通话最后):文件“C:\Users\polly\Desktop\HACK\Discord Bot\Python\bot.py”,第 4 行,在客户端 = discord.Client() AttributeError: module 'discord' has no属性“客户”

Here is my original code:这是我的原始代码:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run(os.getenv('TOKEN'))

Can anyone help?任何人都可以帮忙吗? Thanks!谢谢!

you might need to check your installing portion https://discordpy.readthedocs.io/en/stable/intro.html#installing您可能需要检查您的安装部分https://discordpy.readthedocs.io/en/stable/intro.html#installing

also, through my research, I found this link which is very similar to your code but with a slight difference, and I ran it through my visual code without any problems https://discordpy.readthedocs.io/en/stable/quickstart.html另外,通过我的研究,我发现这个链接与您的代码非常相似,但略有不同,我通过我的可视代码运行它,没有任何问题https://discordpy.readthedocs.io/en/stable/quickstart。 html

It appears you have installed the wrong package, you must install discord.py (by running pip install discord.py or pip3 install discord.py if on Linux), you installed discord which is an outdated mirror of discord.py . It appears you have installed the wrong package, you must install discord.py (by running pip install discord.py or pip3 install discord.py if on Linux), you installed discord which is an outdated mirror of discord.py . To fix this, run:要解决此问题,请运行:

  • pip(3) uninstall discord to remove the old one pip(3) uninstall discord删除旧的
  • pip(3) install discord.py to install the new one pip(3) install discord.py安装新的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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