[英]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,一个用于 discord 组件(按钮、选择、斜线命令等)的 Python 库, 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.