【问题标题】:Discord.py ErrorsDiscord.py 错误
【发布时间】: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


【解决方案1】:

你的文件名是discord.py,重命名文件

将其重命名为 bot.pymain.py 或任何您喜欢的名称,您的问题将得到解决

为什么会这样?

由于您的文件名是 discord.py,它实际上是在导入该文件,而不是您使用 pip 安装的实际 discord.py 模块。

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 2021-04-21
    • 2021-07-10
    • 2021-02-12
    • 1970-01-01
    • 2023-02-11
    • 2021-08-21
    • 2021-06-27
    • 2018-12-22
    相关资源
    最近更新 更多