【问题标题】:How do I send a message with components (buttons) in discord_components? (discord.py)如何在 discord_components 中发送带有组件(按钮)的消息? (discord.py)
【发布时间】:2021-08-12 05:11:30
【问题描述】:

如果不使用 discord_components 模块中的 ctx,我无法弄清楚如何发送消息,该模块扩展了 discord.py 以使用按钮和其他组件。事实是,在某些指南中使用 ctx,但这不适合我。我想根据以下原则发送消息:message.channel.send(embed=embed, components = components),但是在这个模块(discord_components)中我无法弄清楚为什么这对我不起作用,并且为什么我遇到错误“TypeError: send() got an unexpected keyword argument 'components'”。 我也尝试使用“send_component_msg”而不是“send”,但出现错误“属性错误:“TextChannel”对象没有“send_component_msg”属性。

我的代码:

import discord
from discord_components import DiscordComponents, Button, Select, SelectOption

async def info(msg):
    embed = my_embed

    ...

    components = [Button(label = "????"), Button(label = "????"), Button(label = "????"), Button(label = "????")]
    try:
        await message.edit(embed = embed, components = components)
    except Exception:     
        message = await msg.channel.send_component_msg(embed=embed, components = components)

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    虽然我没有使用过discord-components,但我使用过discord-py-slash-commands (https://discord-py-slash-command.readthedocs.io/en/latest/index.html),它支持斜杠命令、按钮和下拉菜单。

    如果你想用discord-py-slash-commands创建一个按钮,很简单,代码如下:

    buttons = [
         create_button(style=ButtonStyle.green, label="?"),               
         create_button(style=ButtonStyle.green, label="?"),
         create_button(style=ButtonStyle.green, label="?")
    ]
    action_row = create_actionrow(*buttons)
    message = await ctx.send("hello there")
    
    await message.edit(components=[action_row])
    

    虽然这不使用 discord-components,但希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 1970-01-01
      • 2022-10-07
      • 2022-01-04
      • 1970-01-01
      • 2021-07-08
      • 2021-08-15
      • 2020-10-01
      • 2021-10-15
      相关资源
      最近更新 更多