我正在尝试编写一个 Discord 机器人,但该机器人无法启动并引发此错误:
I am trying to write a Discord bot, but the bot won't start and raises this error:
AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)
你的标题(在你有任何函数或方法调用之前)应该包括以下项目:
Your header (before you have any functions or method calls) should include the following items:
import discord
from discord.ext import commands
您还需要初始化您的 discord 客户端.在这种情况下,客户端代表您的脚本与不和谐服务器的连接.如果你不初始化,你的命令都不会起作用.
You also need to initialize your discord client. In this case, a client represents your script's connection to the discord server. If you don't initialize, none of your commands will work.
client = commands.Bot(command_prefix=".")
在括号内,您可以声明命令的前缀.例如,.help 与 !help.
within the parenthesis, you can declare the prefix for your commands. Ex, .help vs !help.
最后,您需要将客户端连接到服务器并在连续事件循环中运行它.这应该在文件的末尾.
Lastly, you need to connect your client to the server and run it in a continuous event loop. This should be at the end of your file.
client.run('your bot's token')
这篇关于discord.py 循环导入(AttributeError:部分初始化模块'discord')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)