I have a question

I have a Mute and Unmute command. I would like to know if there is a way to list all Timeout members of a server? If so, how can I do it? Thanks
20 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Danial
Danial11mo ago
You'd need to fetch all the members and then filter the collection
d.js docs
d.js docs11mo ago
method GuildMemberManager#fetch() Fetches member(s) from a method GuildMember#isCommunicationDisabled() Whether this member is currently timed out
!" 𝑱𝒂𝒎𝒆𝒔__
I did it like this, is it good ?
const { CommandInteraction, PermissionsBitField, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, SelectMenuBuilder, ApplicationCommandOptionType, ChannelType } = require("discord.js");

module.exports = {
name: "mute-list",
description: "Permet de voir la liste des users mute",
owner: false,

/**
* @param {Client} client
* @param {CommandInteraction} interaction
*/

run: async (client, interaction) => {
if (!interaction.guild.members.me.permissions.has(PermissionsBitField.Flags.Administrator)) return interaction.reply({ content: `**❌ Les autorisations actuelles sur ce serveur ne me permettent pas d'utiliser cette commande**`, ephemeral: true }).catch(() => { });
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) return interaction.reply({ content: `❌ Vous n'avez pas la permissions de faire cette commande !` })

try {
const guild = interaction.guild;

await guild.members.fetch();

guild.members.cache.forEach((member) => {
if (member.isCommunicationDisabled()) {
console.log(`${member.user.tag} n'es pas timeout.`);
}
});
} catch (error) {
console.log('Une erreur est survenue sur la commande Mute-list', error)
}
}
}
const { CommandInteraction, PermissionsBitField, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, SelectMenuBuilder, ApplicationCommandOptionType, ChannelType } = require("discord.js");

module.exports = {
name: "mute-list",
description: "Permet de voir la liste des users mute",
owner: false,

/**
* @param {Client} client
* @param {CommandInteraction} interaction
*/

run: async (client, interaction) => {
if (!interaction.guild.members.me.permissions.has(PermissionsBitField.Flags.Administrator)) return interaction.reply({ content: `**❌ Les autorisations actuelles sur ce serveur ne me permettent pas d'utiliser cette commande**`, ephemeral: true }).catch(() => { });
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) return interaction.reply({ content: `❌ Vous n'avez pas la permissions de faire cette commande !` })

try {
const guild = interaction.guild;

await guild.members.fetch();

guild.members.cache.forEach((member) => {
if (member.isCommunicationDisabled()) {
console.log(`${member.user.tag} n'es pas timeout.`);
}
});
} catch (error) {
console.log('Une erreur est survenue sur la commande Mute-list', error)
}
}
}
Danial
Danial11mo ago
If it does what you want, sure
!" 𝑱𝒂𝒎𝒆𝒔__
I want to list the users who are mute on my server
Danial
Danial11mo ago
And does what you have there do that?
!" 𝑱𝒂𝒎𝒆𝒔__
I think that currently it allows to list the users who are not mute ??
Danial
Danial11mo ago
No, <GuildMember>.isCommunicationDisabled() returns true if they are timed out, your console log text is wrong
!" 𝑱𝒂𝒎𝒆𝒔__
Oh yes, sorry that's me... How can I make a map to make a list?
Danial
Danial11mo ago
<Collection>.map() exists
!" 𝑱𝒂𝒎𝒆𝒔__
That's it, I did it 🙂
Danial
Danial11mo ago
Awesome!
!" 𝑱𝒂𝒎𝒆𝒔__
I have one last question, to get the reason, how could I do it?
mutedMembers.forEach(member => {
const username = member.user.username;
const reason = member.communicationDisabledReason || "Aucune raison spécifiée"; // Replace with the actual property that stores the mute reason

embed.addFields({ name: `${username}`, value: `Raison : ${reason}`, inline: true});
});
mutedMembers.forEach(member => {
const username = member.user.username;
const reason = member.communicationDisabledReason || "Aucune raison spécifiée"; // Replace with the actual property that stores the mute reason

embed.addFields({ name: `${username}`, value: `Raison : ${reason}`, inline: true});
});
I made this but it doesn't work, it tells me all users mute but not the reasons.
Squid
Squid11mo ago
You have to fetch audit logs to get the reason a member was muted There is no "communicationDisabledReason" property or similar
!" 𝑱𝒂𝒎𝒆𝒔__
Okay, but then I don't know how to go about it...
d.js docs
d.js docs11mo ago
guide Popular Topics: Working with Audit Logs read more
!" 𝑱𝒂𝒎𝒆𝒔__
MemberUpdate ?
Squid
Squid11mo ago
Indeed
!" 𝑱𝒂𝒎𝒆𝒔__
Okay, I did it 🙂
Want results from more Discord servers?
Add your server