Discord.py -按钮并排



我已经为我的Discord bot创建了一些按钮。按钮现在显示在彼此下面,而我宁愿让他们并排而不是。我尝试使用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)

提示吗?

所以答案相当简单。

替换:

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

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

不需要在ActionRow中添加列表。

最后我知道discord.py被放弃了。从那时起,我就一直使用pycord。虽然我没有使用按钮之前,他们有一个行参数为他们的按钮。我建议你看一下pycord或者是你用来给按钮设置row参数的任何不和谐的py文档。参见他们的文档here

的例子:

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

最新更新