【问题标题】:How do i fix discord client command not working in Python如何修复不和谐的客户端命令在 Python 中不起作用
【发布时间】:2019-03-12 01:16:19
【问题描述】:

我目前正在开发一个用 Python 编程语言编写的 Discord 机器人。我看过一些教程,因为我自己无法让它工作,我注意到所有人都使用了 Client = discord.Client() 导入运行程序所需的文件后的命令。当我尝试运行该应用程序时,它说

 Traceback (most recent call last):
File "C:\Users\Admin\Desktop\testbot.py", line 2, in <module>
import discord.client
ModuleNotFoundError: No module named 'discord.client'

如果有人有任何建议,请回复并告诉我! 谢谢!

这是我的机器人代码!

import discord

Client = discord.Client()

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

@client.event
async def on_message(message):
    if message.content == '/testconnection':
        await client.send_message(message.channel, "Connection     successfully established with Discord NET")

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('-------')




client.run("my discord bot token goes here but i'm hiding it ")

【问题讨论】:

    标签: python bots discord discord.py


    【解决方案1】:

    import discord.client 此行不会出现在您发布的代码中的任何位置。

    您将discord.Client() 分配给Client,但在其余代码中使用client。名称区分大小写,因此您应该将该行更改为

    client = discord.Client()
    

    【讨论】:

    • 我已经修复了大写错误,但是当我尝试导入 discord.client 时,我得到了这个 Traceback(最近一次调用最后):文件“C:\Users\Admin\Desktop\testbot.py ",第 2 行,在 中 import discord.Client ModuleNotFoundError: No module named 'discord.Client'
    • 只需import discord,然后使用discord.Client 在您的代码中引用该类。
    • 它说没有名为 Client 的属性
    猜你喜欢
    • 2021-10-02
    • 2021-10-05
    • 2022-01-06
    • 2021-08-12
    • 2020-02-14
    • 2021-09-27
    • 2019-11-04
    • 2019-02-20
    • 1970-01-01
    相关资源
    最近更新 更多