简体   繁体   中英

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).

I tried to block @everyone 's CONNECT permission but I could not manage to define it. 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. 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 . 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.

In your example, you can do:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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