Discord.net如何提及角色

时间:2020-05-21 14:52:15

标签: discord.net

如何通过Discord.net库在C#中提及行会角色?

4 个答案:

答案 0 :(得分:1)

您也可以使用iRole

[Command("roleinfo")]
    public async Task mentionRoleAsync(IRole role)
    {

        var embed = new EmbedBuilder();
        embed.WithDescription("Role ID : " + role.Id + Environment.NewLine + "Role Name : " + role.Name + Environment.NewLine + "Role Mention : " + role.Mention + Environment.NewLine + "Role Mention : " + role.Mention + Environment.NewLine + "Role Color : " + role.Color.ToString() + Environment.NewLine + "Role Created at : " + role.CreatedAt);
        await Context.Channel.SendMessageAsync("", false, embed);

    }

Result

答案 1 :(得分:0)

我找到了一种方法:

MentionUtils.MentionRole(id)

答案 2 :(得分:0)

还可以使用角色的原始提及,即角色对象中.Mention属性的内容。

格式如下:

<@&ROLE_ID>

与用&字符提及单个用户不同,后者指定的是提及角色而不是用户。

如果要对其进行硬编码,则可以从.ID属性中获取角色ID,或者在角色列表中右键单击该角色。

以名称提及角色的示例命令:

        [Command("mention")]
        public async Task MentionRole(string name)
        {
            SocketRole role = Context.Guild.Roles.First(x => x.Name == name); //Get the first role that matches the name provided

            await ReplyAsync($"<@&{role.Id}>"); //Format the string that mentions the role (ex. <@&739515238742753371>)
            await ReplyAsync(role.Mention); //Optionally, you can use the integrated property that returns the exact same string as we formatted above

            //The mention is instantly sent as a reply to the command
        }

答案 3 :(得分:0)

那是一个例子,你必须使用 IRole,如果你想提及它,那么只需发送消息:<&ROLEID>

[Command("role")]
    public async Task mentionRoleAsync(IRole role)
    {

        var embed = new EmbedBuilder()
        .WithTitle("Role Infos")
        .WithDescription($"Role ID{role.Id} \n Name: {role.Name}");


    }