【问题标题】:Add buttons with responses to an embed discord.py添加带有对嵌入 discord.py 响应的按钮
【发布时间】:2022-01-11 03:01:13
【问题描述】:

我一直在寻找适用于我的代码的答案,但老实说我找不到。我知道如何创建按钮并将它们添加到嵌入的底部,但我无法让它们发送隐藏消息。这是我的按钮代码:

buttons = [
  create_button(style=ButtonStyle.green, label="I liked it"), 
  create_button(style=ButtonStyle.grey, label="I'm neutral"), 
  create_button(style=ButtonStyle.red, label="I did not like it")
]
action_row = create_actionrow(*buttons)

bcc2 = await bcc.send(embed=embed, components=[action_row])

它是在一天的特定时间发生的重复功能。但是,当我尝试链接响应时,它会完全忽略它。有什么建议吗?这是我的回复尝试:

@slash.component_callback()
async def hello(ctx: ComponentContext):
    await ctx.send(content="You pressed a button!", hidden=True)

最后我希望发送的消息是隐藏消息。

【问题讨论】:

  • 您使用什么软件包来制作按钮和执行斜线命令?据我所知,discord.py 无法发送隐藏消息。但有些包提供了一种发送“临时消息”作为对斜杠命令和其他组件的响应的方法。

标签: python discord discord.py


【解决方案1】:

你不能用 discord.py 做到这一点,但你可以用 pycord 做到这一点,它是 discord.py 的一个分支。 最新版本的 pycord (2.0.0) 支持斜杠命令、消息组件和临时消息。

您可以通过在终端中运行它来安装它:

pip install -U git+https://github.com/Pycord-Development/pycord

要让机器人发送隐藏消息,请执行以下操作:

await ctx.send('This is a hidden message', ephemeral=True)

您也可以在 pycord 中使用内置的斜杠命令功能,而无需安装第三方库。您可以查看文档here 了解更多信息。 This tutorial 解释了如何使用 pycord 创建视图和按钮。

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 1970-01-01
    • 2021-08-16
    • 2021-09-26
    • 2022-11-16
    • 2021-12-20
    • 2021-07-03
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多