简体   繁体   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)

i tried to do this but throws error that says str has no attribute mentions我尝试这样做但抛出错误,指出 str 没有属性提及

i am trying to get all mentioned roles ids in pycord and got error我试图在 pycord 中获取所有提到的角色 ID,但出现错误

You've not specified the type for the mention parameter - by default this is a string (hence your error that "str has no attribute mentions").您没有指定mention参数的类型 - 默认情况下这是一个字符串(因此您的错误是“str 没有提及属性”)。 The first arg to discord.Option should be the type of the option - the library will then convert that and allow you to select mentionables when using the slash command and you'll have a mentionable object type in the code when the slash command is used. discord.Option的第一个参数应该是选项的类型 - 然后库将转换它并允许您在使用斜杠命令时使用 select 可提及的内容,并且在使用斜杠命令时您将在代码中输入可提及的 object . Perhaps consider re-reading this section in the guides. 也许考虑重新阅读指南中的这一部分。

@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