简体   繁体   English

我如何定义@everyone? (discord.js)

[英]How can I define @everyone? (discord.js)

I'm trying to create private channel script in discord.js v12 that once a member joins, it creates a private room which only the person who created can join and others can't (only with a command).我正在尝试在 discord.js v12 中创建私人频道脚本,一旦成员加入,它就会创建一个私人房间,只有创建的人可以加入,其他人不能(只能使用命令)。

I tried to block @everyone 's CONNECT permission but I could not manage to define it.我试图阻止@everyoneCONNECT权限,但我无法定义它。 I tried to define it via ID , using const while referring to settings.json , also tried to use guild.defaultRole , etc. but none of them worked.我尝试通过ID定义它,在引用settings.json时使用const ,还尝试使用guild.defaultRole等,但它们都不起作用。 Can someone help me with my script?有人可以帮我写剧本吗?

const { VoiceState } = require('discord.js');
const SettingsJSON = require('../../Configuration/Settings.json');
const Settings = SettingsJSON.PrivHub;

module.exports = async (oldState, newState) => {
  let mainChannel = oldState.guild.channels.cache.get(Settings.Room);
  if (!mainChannel) return;

  if (
    !oldState.channelID &&
    newState.channelID &&
    newState.channel.parentID == mainChannel.parentID &&
    newState.channelID == mainChannel.id
  ) {
    newState.guild.channels
      .create(
        `${Settings.Symbol} ${newState.member.displayName} kişisinin odası`,
        {
          type: 'voice',
          parent: mainChannel.parentID,
          permissionOverwrites: [
            mainChannel.permissionOverwrites.clone().set(
              newState.member.id,
              {
                id: newState.member.id,
                allow: [
                  'MANAGE_CHANNELS',
                  'STREAM',
                  'VIEW_CHANNEL',
                  'CONNECT',
                  'SPEAK',
                  'USE_VAD',
                ],
              },
              {
                id: everyone /*// problem is here /*/,
                deny: ['CONNECT'],
              },
            ),
          ],
        },
      )
      .then((channel) => {
        if (newState.member && newState.member.voice.channelID)
          newState.member.voice.setChannel(channel);
      });
    return;
  } else if (oldState.channelID && newState.channelID) {
    let oldChannel = oldState.channel;
    if (
      oldChannel.position > mainChannel.position &&
      oldChannel.parentID == mainChannel.parentID &&
      oldChannel.members.size <= 0 &&
      !oldChannel.deleted
    )
      oldChannel.delete().catch(undefined);
    if (
      newState.channelID == mainChannel.id &&
      newState.channel.parentID == mainChannel.parentID
    ) {
      newState.guild.channels
        .create(
          `${Settings.Symbol} ${newState.member.displayName} kişisinin odası`,
          {
            type: 'voice',
            parent: mainChannel.parentID,
            permissionOverwrites: [
              mainChannel.permissionOverwrites.clone().set(
                newState.member.id,
                {
                  id: newState.member.id,
                  allow: [
                    'MANAGE_CHANNELS',
                    'STREAM',
                    'VIEW_CHANNEL',
                    'CONNECT',
                    'SPEAK',
                    'USE_VAD',
                  ],
                },
                {
                  id: everyone /*// problem is here //*/,
                  deny: ['CONNECT'],
                },
              ),
            ],
          },
        )
        .then((channel) => {
          if (newState.member && newState.member.voice.channelID)
            newState.member.voice.setChannel(channel);
        });
    }
    return;
  } else if (
    oldState.channelID &&
    oldState.channel.parentID == mainChannel.parentID &&
    !newState.channelID
  ) {
    let oldChannel = oldState.channel;
    if (
      oldChannel.position > mainChannel.position &&
      oldChannel.members.size <= 0 &&
      !oldChannel.deleted
    )
      oldChannel.delete().catch(undefined);
  }
};

module.exports.config = {
  Event: 'voiceStateUpdate',
};

You can either use roles.everyone that returns the @everyone role of the guild or simply use the guild's ID .您可以使用roles.everyone返回公会的@everyone角色,也可以简单地使用公会的 ID Any of these will work:这些中的任何一个都可以:

{
  id: oldState.guild.roles.everyone.id,
  deny: ['CONNECT'],
};

Or:或者:

{
  id: oldState.guild.id,
  deny: ['CONNECT'],
};

Or:或者:

{
  id: newState.guild.roles.everyone.id,
  deny: ['CONNECT'],
};

Or:或者:

{
  id: newState.guild.id,
  deny: ['CONNECT'],
};

You can find the everyone role with the RoleManager#everyone getter.您可以使用RoleManager#everyone getter 找到每个人的角色。

In your example, you can do:在您的示例中,您可以执行以下操作:

id: oldState.guild.roles.everyone.id,
deny: ["CONNECT"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM