python - 如何修复不和谐的客户端命令在 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 ")
解决方案
import discord.client
此行不会出现在您发布的代码中的任何位置。
您分配discord.Client()
给Client
,但client
在其余代码中使用。名称区分大小写,因此您应该将该行更改为
client = discord.Client()
推荐阅读
- arrays - Laravel - 在字符串上调用成员函数 save()
- javascript - 卸载的组件仍然首先渲染
- python - 如何从 Python 中此对象返回的字典中访问特定值
- nearprotocol - 使用 NEAR Lib 生成密钥对
- javascript - 通过 Chrome 使用 pdf 文档的窗口事件
- java - 尝试为 android 实现 google 登录时出现错误代码 12500
- javascript - 制作 GUI 时如何将 Go 脚本与 Gotron 前端连接?
- java - 在 JWT 用户映射期间创建 Gentics Mesh 用户配置文件节点 - 导致失败
- javascript - 为什么 .data="[filepath]" 在 Internet Explorer 中不起作用?
- docker - 如何设置 influx docker 容器监听特定端口地址上的 collectd?