discord.py-并排按钮
我为我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此答案很简单。
对于那些想知道的人...
替换:
by:
不需要在Actionrow中添加列表。
So the answer was fairly simple.
For those who wonder...
Replace:
By:
There's no need to add a list to the ActionRow.
最后我知道Discord.py被遗弃了。我已经使用 pycord 此后。尽管我没有在按钮上使用按钮来进行按钮的按钮。我建议您查看pycord,或者您使用的任何discord。请参阅他们的文档
示例:
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 docshere
Example: