[英]How do i disable a D#+ Command To not show for users who dont have certain permissions?
如何禁用 D#+ 命令以不向没有特定权限(例如管理员或所有者)的用户显示?
答复将不胜感激,谢谢。
向不应访问命令的人隐藏命令的最简单方法是使用属性。
[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!"));
}
您可以将属性更改为在DSharpPlus.Permissions中找到的任何权限
您也可以为此使用角色:
[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可用于在涉及多个角色时定义参数,您可以在此处找到有关此属性的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.