You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pycord分页器:如何让页码在导航按钮间居中显示?

Pycord分页器页码居中实现方案

要实现页码在导航按钮中间居中,同时解决切换页面时的偏移问题,无需完全自定义导航按钮,可通过Pycord原生的pages.Paginator的buttons参数自定义按钮布局来实现:

代码修改示例

@commands.slash_command()
async def help(self, ctx):
    """显示帮助页面"""
    paginator = pages.Paginator(
        pages=self.pages,
        show_disabled=False,
        # 自定义按钮顺序:上一页 → 页码 → 下一页
        buttons=[
            pages.PaginatorButton("prev", label="←", style=discord.ButtonStyle.secondary),
            pages.PaginatorButton("page_counter", style=discord.ButtonStyle.secondary, disabled=True),
            pages.PaginatorButton("next", label="→", style=discord.ButtonStyle.secondary),
        ]
    )
    await paginator.respond(ctx.interaction, ephemeral=False)
    await Session.delete_message(self, ctx, 60)

说明

  • 通过buttons参数重新定义按钮排列顺序,将page_counter(页码组件)放在左右导航按钮中间,直接实现居中显示效果。
  • 该方式完全复用Pycord原生分页逻辑,无需自行编写页面切换交互代码,同时固定了页码位置,解决了切换页面时的偏移问题。

内容的提问来源于stack exchange,提问作者Efipee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 03:05:25