【发布时间】:2021-08-14 12:47:15
【问题描述】:
今天我想尝试用 python 创建一个不和谐的机器人。我遇到的问题是,启动程序时总是出现错误消息:
Traceback (most recent call last):
File "D:\...\Discord Bot\PythonGPU_Bot\bot.py", line 1, in <module>
import discord
File "C:\Users\...\Python\Python39\lib\discord\__init__.py", line 4, in <module>
client = discord.Client()
AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)
这就是我经常收到的错误消息。 这是我的脚本:
import discord
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as {}'.format(client.user.name))
client.loop.create_task(status_task())
async def status_task():
while True:
await client.change_presence(activity=discord.Game('Hello <:'))
await asyncio.sleep(1)
await client.change_presence(activity=discord.Game('Hello c:'))
await asyncio.sleep(1)
@client.event
async def on_message(message):
if message.auther.bot:
return
if '.status' in message.content:
await message.channel.send('SSSS')
client.run('ID')
希望有人能帮帮我。
【问题讨论】:
-
这对您有帮助吗? Discord Bot Coding (AttributeError: partially initialized module..) - 另外:你更新你的
discord.py版本了吗? -
我已经看过那个帖子,但它并没有帮助我。我还更新了 discord.py 也许我必须重新安装它,但我不知道如何。
-
您是否也尝试删除您的客户端并将其替换为:
client = commands.Bot(command_prefix="!")并导入from discord.ext import commands? 请注意,这将为您的机器人支持commands -
是的,我试过了,同样的问题出现了
-
其实是循环导入造成的。重命名您的文件!
标签: python error-handling discord discord.py