Discord.py 按钮错误意外的关键字

时间:2021-06-15 02:02:47

标签: discord discord.py

这是我的代码:

async def test(ctx):
    await ctx.send(
        "Discord Buttons!",
        components=[
            [Button(style=ButtonStyle.red, label="Red"),
             Button(style=ButtonStyle.red, label="Red", disabled=True),
             Button(style=ButtonStyle.URL, label="Youtube", url="https://youtube.com")],
             Button(style=ButtonStyle.blue, label="Blue", emoji="?"),
        ],
    )
    res = await bot.wait_for("button_click")
    if res.channel == ctx.message.channel:
        await res.repond(
            type=InteractionType.ChannelMessageWithSource,
            content=f"Pressed!"
        )

这是它不断给出的错误:

Command raised an exception: TypeError: send() got an unexpected keyword argument 'components'

我正在尝试创建一个命令,如果您说 $test,它会以按钮响应:https://support.discord.com/hc/article_attachments/1500019725621/buttons.png

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试使用 discord-components。为此,您需要使用 pip install discord-components 安装软件包,然后将以下内容添加到您的代码中(如果您还没有这样做)。

from discord.ext.commands import Bot
from discord_components import DiscordComponents, Button

bot = Bot('$') # Prefix

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

# ...

然后,您应该能够添加一个 components 字段以在其中发送 Button