如果频道不是 NSFW,如何从帮助菜单中隐藏 NSFW 命令

时间:2021-02-17 13:29:43

标签: javascript node.js discord.js

我有一个帮助菜单和一些命令。还有一些 NSFW 命令,如果频道没有标记为 NSFW,我希望这些命令不显示。

这是我当前的代码:

case 'help':
  if (message.author.bot) return;
  if (message.channel.type === 'dm') return;
  if (message.content.startsWith(';')) {
    const embed10 = new Discord.MessageEmbed();
    embed10.setColor([133, 0, 255]);
    embed10.setTitle('Command List');
    embed10.addField(
      '? Emotes',
      '`smile` `sad` `cry` `sleepy` `angry` `happy` `blush` `baka` `confused` `pout` `die` `scared` `laugh` `bai` `run` `drunk` `eat` `drink` `hungry` `facepalm`',
    );
    embed10.addField(
      '? NSFW',
      '`rhentai` `ngif` `wallpaper` `feet` `boobs` `ahegao`',
    );
    embed10.addField(
      '? Utility',
      '`botinfo` `weather` `uptime` `say` `hammer` `advice` `vibingcat`  `bongo` `ping` `Axmyo` `drawing`',
    );

    message.channel.send(embed10);
  }
  break;

1 个答案:

答案 0 :(得分:2)

message.channel 上有一个 nsfw property,您可以检查它并根据它添加 NSFW 字段:

switch (command) {
  case 'help':
    if (message.author.bot) return;
    if (message.channel.type === 'dm') return;
    if (message.content.startsWith(';')) {
      const embed10 = new Discord.MessageEmbed();
      embed10.setColor([133, 0, 255]);
      embed10.setTitle('Command List');
      embed10.addField(
        '? Emotes',
        '`smile` `sad` `cry` `sleepy` `angry` `happy` `blush` `baka` `confused` `pout` `die` `scared` `laugh` `bai` `run` `drunk` `eat` `drink` `hungry` `facepalm`',
      );
      if (message.channel.nsfw) {
        embed10.addField(
          '? NSFW',
          '`rhentai` `ngif` `wallpaper` `feet` `boobs` `ahegao`',
        );
      }
      embed10.addField(
        '? Utility',
        '`botinfo` `weather` `uptime` `say` `hammer` `advice` `vibingcat`  `bongo` `ping` `Axmyo` `drawing`',
      );

      message.channel.send(embed10);
    }
    break;
}