如何添加这些带有图像的按钮?

2024-07-01 07:42:19 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能帮我添加这些带有图片的按钮吗?我正在尝试,但无法在python中为discord bot添加图像。在这里,我留下了我的意思的截图:

https://i.stack.imgur.com/LJU07.png

这是我的密码

from discord import Client
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

bot = Client()

@bot.event
async def on_ready():
    DiscordComponents(bot)

@bot.event
async def on_message(msg):
    if msg.author.bot:
        return

    await msg.channel.send(
        "Content",
        components=[
            Button(style=ButtonStyle.blue, label="Blue"),
            Button(style=ButtonStyle.red, label="Red"),
            Button(style=ButtonStyle.URL, label="url", url="https://example.org"),
        ],
    )

    res = await bot.wait_for("button_click")
    if res.channel == msg.channel:
        await res.respond(
            type=InteractionType.ChannelMessageWithSource,
            content=f'{res.component.label} clicked'
        )
            
bot.run("")    

Tags: fromimportclientstylebotchannelcomponentsbutton

热门问题