【问题标题】:Server roles command Discord.py服务器角色命令 Discord.py
【发布时间】:2021-04-09 15:10:51
【问题描述】:

所以最近我试图在我的不和谐机器人中创建服务器角色命令,这将显示服务器中存在的所有角色。我想将它们设置在单列而不是行中。我无法这样做。我可以进行哪些更改以在单个列中显示它[对不起,如果我无法让你正确理解,因为我的英语有点差。] 任何帮助表示赞赏!

我希望它是怎样的:

它是怎样的:

我当前的代码:

@commands.command(pass_context=True)
    async def roles(self, ctx):
        guild = ctx.guild
        roles = [role for role in guild.roles if role != ctx.guild.default_role]
        embed = discord.Embed(title="Server Roles", description=f" ".join([role.mention for role in roles]))
        await ctx.send(embed=embed)

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    如果禁用了描述的 HTML 转义,则将连接字符串更改为 description=f"<br>".join([role.mention for role in roles]) 将起作用。

    【讨论】:

    • 它刚刚将
      @role1
      @role2
      @role3 添加到整个列表中抱歉,但使用 \n 代替 <br> 有效!还是谢谢
    • 有趣的是,当 OP 在此答案中使用原始想法来解决问题时,看到否决票。
    • @Niloct:我不能代表反对者发言,但我的猜测是:答案末尾的问号使这看起来像是一个问题,而不是一个建议。添加更多解释可能有助于避免这种混淆——当然,这通常是一种最佳做法。
    【解决方案2】:

    您需要在提及角色后添加\n。这将在嵌入中开始一个新行。

    【讨论】:

    • 我正想问如何使用它,但我刚刚添加了它description = f"\n".join...,它工作了谢谢
    猜你喜欢
    • 2021-07-17
    • 2021-07-06
    • 2021-02-07
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2022-01-10
    相关资源
    最近更新 更多