Discord.js 14 如何显示按用户角色过滤的命令列表中的命令?

问题描述 投票:0回答:1

可以做到我在标题中所写的。当机器人准备就绪时,我已经加载了命令,但我只想根据用户的角色向用户显示命令,预先感谢

// loading all commands example
CommandList.forEach((command) => {
      commandData.push(
        command.data.toJSON() as {
          name: string;
          description?: string;
          type?: number;
          options?: APIApplicationCommandOption[];
        },
      );
    });

    const response = (await rest.put(
      Routes.applicationGuildCommands(BOT.user?.id || "missing token", process.env.GUILD_ID as string),
      {
        body: commandData,
      },
    )) as [];

    logger.debug(`Successfully reloaded ${response.length} application (/) commands.`);
node.js discord.js roles
1个回答
0
投票

您可以使用

default_member_permissions
属性

在此代码中,

8
Administrator
权限位字段,因此只有管理员可以执行此命令。

const command = {
  name: "sample",
  description: "sample command",
  default_member_permissions: "8"
}

权限位域文档

© www.soinside.com 2019 - 2024. All rights reserved.