AttributeError: module 'discord' has no attribute 'ui' when trying to create button in discord.py

AttributeError: module 'discord' has no attribute 'ui' when trying to create button in discord.py

我想知道如何使用 discord.py 制作按钮。

这就是我想要的示例:

我的代码:

import discord
from discord.ext import commands 

client=commands.Bot(command_prefix=".")

class Buttons(discord.ui.View):
    def __init__(self, *, timeout=180):
        super().__init__(timeout=timeout)
    @discord.ui.button(label="Button",style=discord.ButtonStyle.gray)
    async def gray_button(self,button:discord.ui.Button,interaction:discord.Interaction):
        await interaction.response.edit_message(content=f"This is an edited button response!")

@client.command()
async def button(ctx):
    await ctx.send("This message has buttons!",view=Buttons())

token=""
client.run(token)

错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord' has no attribute 'ui'

您需要使用 pip install -U git+https://github.com/Rapptz/discord.py

更新到版本 2.0 而不是 1.7.3