[英]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.