[英]How do i disable a D#+ Command To not show for users who dont have certain permissions?
how do i disable a D#+ Command to not show for users who don't have specific permissions such as Administrator, Or Owner?如何禁用 D#+ 命令以不向没有特定权限(例如管理员或所有者)的用户显示?
a reply would be appreciated, thanks.答复将不胜感激,谢谢。
The easiest way to hide a command from someone who should not have access to it is with attribution.向不应访问命令的人隐藏命令的最简单方法是使用属性。
[SlashCommand("hello", "hello world")]
[RequirePermissions(DSharpPlus.Permissions.Administrator)] //Must have admin perm to see/use
public static async Task HelloWorld(InteractionContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder().WithContent("Hello, World!"));
}
You can change the attribution to any of the permissions found in DSharpPlus.Permissions您可以将属性更改为在DSharpPlus.Permissions中找到的任何权限
You can also use roles for this as well:您也可以为此使用角色:
[SlashCommand("hello", "hello world")]
[RequireRoles(RoleCheckMode.Any, new ulong[] { 99999 })] // must have role with ID 99999
public static async Task HelloWorld(InteractionContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder().WithContent("Hello, World!"));
}
RoleCheckMode can be used to define parameters for when you have multiple roles involved, and you can find more about this attribution here RoleCheckMode可用于在涉及多个角色时定义参数,您可以在此处找到有关此属性的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.