簡體   English   中英

如何在斜杠命令pycord中獲取提到的角色ID

[英]How to get mentioned roles ids in slash command pycord

@bot.slash_command(name = "test", description = "testing command")
async def test(ctx, mention: discord.Option(name="mention", description="mention.", required=True)):
        print(mention.mentions.role_mentions)

我嘗試這樣做但拋出錯誤,指出 str 沒有屬性提及

我試圖在 pycord 中獲取所有提到的角色 ID,但出現錯誤

您沒有指定mention參數的類型 - 默認情況下這是一個字符串(因此您的錯誤是“str 沒有提及屬性”)。 discord.Option的第一個參數應該是選項的類型 - 然后庫將轉換它並允許您在使用斜杠命令時使用 select 可提及的內容,並且在使用斜杠命令時您將在代碼中輸入可提及的 object . 也許考慮重新閱讀指南中的這一部分。

@bot.slash_command(name = "test", description = "testing command")
async def test(
    ctx,
    mention: discord.Option(
        discord.SlashCommandOptionType.mentionable,
        name="mention",
        description="mention.",
        required=True
    )
):
    # whatever you want to do with that here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM