discord.py-并排按钮

发布于 2025-02-11 02:07:17 字数 713 浏览 1 评论 0原文

我为我的Discord机器人创建了一些按钮。现在,这些按钮互相出现在彼此的下方,而我宁愿将它们并排放置。 我尝试为此使用ActionRow,但这似乎并没有改变任何事情。 仅供参考,我正在使用Discord.py 1.7.3,所以不是v2.0。

当前代码:

import discord
from discord.ext import commands
import random
import time
from discord_components import *

bot = commands.Bot(command_prefix="!")

@bot.command()
async def test(ctx):
    button = Button(
        style=ButtonStyle.blue,
        custom_id="primary",
        label="Blue button",
    )
    button2 = Button(
        style=ButtonStyle.red,
        custom_id="secondary",
        label="Red button",
    )
    action_row = ActionRow(components=[button, button2])
    await ctx.send("Hello World!", components=action_row)

有技巧吗?

I've created some buttons for my Discord bot. The buttons now show up underneath each other while I'd rather have them side-by-side instead.
I tried using an ActionRow for this, but that doesn't seem to change anything.
Fyi, I'm using Discord.py 1.7.3, so not v2.0.

The current code:

import discord
from discord.ext import commands
import random
import time
from discord_components import *

bot = commands.Bot(command_prefix="!")

@bot.command()
async def test(ctx):
    button = Button(
        style=ButtonStyle.blue,
        custom_id="primary",
        label="Blue button",
    )
    button2 = Button(
        style=ButtonStyle.red,
        custom_id="secondary",
        label="Red button",
    )
    action_row = ActionRow(components=[button, button2])
    await ctx.send("Hello World!", components=action_row)

Any tips?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潜移默化 2025-02-18 02:07:17

因此答案很简单。
对于那些想知道的人...

替换:

    action_row = ActionRow(components=[button, button2])
    await ctx.send("Hello World!", components=action_row)

by:

    action_row = ActionRow(button, button2)
    await ctx.send("Hello World!", components=[action_row])

不需要在Actionrow中添加列表。

So the answer was fairly simple.
For those who wonder...

Replace:

    action_row = ActionRow(components=[button, button2])
    await ctx.send("Hello World!", components=action_row)

By:

    action_row = ActionRow(button, button2)
    await ctx.send("Hello World!", components=[action_row])

There's no need to add a list to the ActionRow.

じее 2025-02-18 02:07:17

最后我知道Discord.py被遗弃了。我已经使用 pycord 此后。尽管我没有在按钮上使用按钮来进行按钮的按钮。我建议您查看pycord,或者您使用的任何discord。请参阅他们的文档

示例:

button = Button(
    style=ButtonStyle.blue,
    custom_id="primary",
    label="Blue button",
    row=1,
)

Last I knew discord.py was abandoned. I have used pycord since then. Although I have not used buttons before they have a row argument for their buttons. I'd suggest taking a look at pycord or maybe whatever discord.py docs you are using for a row argument to buttons. See their docs here

Example:

button = Button(
    style=ButtonStyle.blue,
    custom_id="primary",
    label="Blue button",
    row=1,
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文