如何将按钮添加到 discord.py 中的嵌入

How to add buttons to an embed in discord.py

所以我和我的朋友有一个嵌入,

@client.event
async def on_message(message):
    if message.content.lower().startswith("!help"):
        HelpEmbed = discord.Embed(
            title="Help screen",
            description=
            "Here is you can find instructions of how to use the bot!",
            color=discord.Colour.blue())
        HelpEmbed.add_field(
            name="Game Commands",
            value=
            "These are commands to do stuff in the game, use !GameCMDS to see all commands relate to the game",
            inline=False)
        HelpEmbed.add_field(
            name="Server commands",
            value=
            "These are commands to do stuff with the server. Use !ServerCMDS to see all commands related to the server",
            inline=False)
        HelpEmbed.set_thumbnail(
            url=
            "https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1244&q=80"
        )
        await message.channel.send(embed=HelpEmbed) 

我们想给它添加按钮,但是所有教程都不起作用。我的朋友也不知道怎么做,所以如果你知道请告诉我,如果你能告诉我如何添加页脚因为 HelpEmbed.set_footer 不起作用。谢谢!

看看 discord-ineraction,一个 python discord 组件库(按钮、选择、斜线命令...) GitHub, Docs

首先,安装库

$ pip install -U discord-py-interactions

根据文档,您可以使用 create_button:

from discord_slash.utils.manage_components import create_button, create_actionrow
from discord_slash.model import ButtonStyle

# ...

buttons = [
            create_button(
                style=ButtonStyle.green,
                label="A Green Button"
            ),
          ]

action_row = create_actionrow(*buttons)

await message.channel.send(embed=HelpEmbed, components=[action_row])

页脚可以设置embed.set_footer():

embed.set_footer(text="My Footer")