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

问题描述 投票:0回答:1

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

@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
不起作用。谢谢!

python discord discord.py discord-buttons
1个回答
1
投票

Discord.py v2:

自discord.py 2.0发布以来,现在可以进行交互 https://discordpy.readthedocs.io/en/v2.3.2/api.html#discord.Message.components

旧答案:

看一下discord-ineraction,一个用于discord 组件(按钮、选择、斜线命令等)的Python 库 GitHub文档

首先,安装库

$ 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")
© www.soinside.com 2019 - 2024. All rights reserved.