如何在Discord.net库中提到C#中的行会角色?
发布于 2020-05-22 04:00:02
我找到了一种方法来做到这一点:
MentionUtils.MentionRole(id)发布于 2020-08-11 22:08:36
也可以使用角色的原始提及,即角色对象中.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
}发布于 2020-08-25 18:30:01
您也可以使用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);
}

https://stackoverflow.com/questions/61937284
复制相似问题