【问题标题】:AttributeError: module 'discord' has no attribute 'ui'AttributeError:模块'discord'没有属性'ui'
【发布时间】:2022-05-12 03:26:02
【问题描述】:

问题标题定义了问题。我使用以下内容安装了discord.py 模块:

pip install -U git+https://github.com/Rapptz/discord.py

但是,当我尝试运行我的代码时:

import discord

class JoinQueue_Button(discord.ui.View):
    @discord.ui.button(label='Join This Game!', style=discord.ButtonStyle.green)
    async def queue(self, interaction: discord.Interaction):
        current_queue = {}

        await interaction.user.id

我收到一条错误消息,提示 ui 模块不存在。我现在不确定该怎么做。

【问题讨论】:

  • 您有自己的名为discord.py的本地文件吗?
  • 不,我不知道。我需要一个吗?
  • 不,事实上你不应该拥有一个。但如果你这样做了,就可以解释这个错误。
  • 这对您有帮助吗? Add button components to a message (discord.py)。您要做的是在v2.0 of discord.py
  • discord-ui 是一个独立于 discord 的包。

标签: python discord.py


【解决方案1】:

我认为它可能已经过时了。

尝试运行下一个命令:pip install --upgrade discord.py

【讨论】:

  • 也试过了,也遇到了同样的问题。我整天都在卸载和重新安装。
【解决方案2】:

试试这个:

  • Windowspy -m pip install discord-ui
  • Linuxpython3 -m pip install discord-ui

同时检查here

【讨论】:

  • 我还需要在任何地方添加import ui吗?
【解决方案3】:

我解决了运行这个问题

python3 -m pip install -U py-cord --pre

【讨论】:

    猜你喜欢
    • 2022-07-23
    • 2018-04-14
    • 2019-02-18
    • 1970-01-01
    • 2020-01-01
    • 2019-07-20
    • 2021-11-05
    • 2021-11-04
    相关资源
    最近更新 更多