首页 > 解决方案 > 如何修复不和谐的客户端命令在 Python 中不起作用

问题描述

我目前正在开发一个用 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 ")

标签: pythonbotsdiscorddiscord.py

解决方案


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

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

client = discord.Client()

推荐阅读