discord.py circular import (AttributeError: partially initialized module #39;discord#39;)(discord.py 循环导入(AttributeError:部分初始化模块discord))
问题描述
我正在尝试编写一个 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')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:discord.py 循环导入(AttributeError:部分初始化模块'discord')


- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01