_Arava_
_Arava_
DIAdiscord.js - Imagine an app
Created by _Arava_ on 7/20/2023 in #djs-questions
Get all users which have permission "Connect" on false in a specific voice channel
Full Code
const { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder, Client, PermissionsBitField, ChannelType, GuildMember} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName("vstatus")
.setDescription("...")
.addChannelOption(option => option
.setName("vocal")
.setDescription("...")
.setRequired(false)
),
/**
*
* @param {ChatInputCommandInteraction} interaction
* @param {Client} client
*/
async execute(interaction, client) {
const { member, guild } = interaction;
const { channel } = await member.voice;

var vocal = interaction.options.getChannel("vocal") || channel;

const EmbedYouAreNotInVocal = new EmbedBuilder()
.setDescription("**Vous devez être dans un salon vocal ou préciser un vocal pour utiliser cette commande !**")

const EmbedNotAVocal = new EmbedBuilder()
.setDescription("**Le salon vocal mentionné n'est pas un salon vocal !**")

if (vocal.type !== ChannelType.GuildVoice) return interaction.reply({
embeds: [ EmbedNotAVocal ]
})

if (!vocal) {
interaction.reply({
embeds: [ EmbedYouAreNotInVocal ]
})
} else {
var channelPerm = await vocal.permissionsFor(guild.roles.everyone.id);

//fetch guild members
await guild.members.fetch();
//have permission to connect on false
var banneds = guild.members.cache.filter(m => !m.permissionsIn(vocal).has(PermissionsBitField.Flags.Connect));
console.log(banneds);// return "Collection(0) [Map] {}"

interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle(`**STATUS DU VOCAL "${vocal.name}"**`)
.setDescription(
`- \`bans\` : FutureList...\n`
)
]
});
}
}
}
const { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder, Client, PermissionsBitField, ChannelType, GuildMember} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName("vstatus")
.setDescription("...")
.addChannelOption(option => option
.setName("vocal")
.setDescription("...")
.setRequired(false)
),
/**
*
* @param {ChatInputCommandInteraction} interaction
* @param {Client} client
*/
async execute(interaction, client) {
const { member, guild } = interaction;
const { channel } = await member.voice;

var vocal = interaction.options.getChannel("vocal") || channel;

const EmbedYouAreNotInVocal = new EmbedBuilder()
.setDescription("**Vous devez être dans un salon vocal ou préciser un vocal pour utiliser cette commande !**")

const EmbedNotAVocal = new EmbedBuilder()
.setDescription("**Le salon vocal mentionné n'est pas un salon vocal !**")

if (vocal.type !== ChannelType.GuildVoice) return interaction.reply({
embeds: [ EmbedNotAVocal ]
})

if (!vocal) {
interaction.reply({
embeds: [ EmbedYouAreNotInVocal ]
})
} else {
var channelPerm = await vocal.permissionsFor(guild.roles.everyone.id);

//fetch guild members
await guild.members.fetch();
//have permission to connect on false
var banneds = guild.members.cache.filter(m => !m.permissionsIn(vocal).has(PermissionsBitField.Flags.Connect));
console.log(banneds);// return "Collection(0) [Map] {}"

interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle(`**STATUS DU VOCAL "${vocal.name}"**`)
.setDescription(
`- \`bans\` : FutureList...\n`
)
]
});
}
}
}
3 replies