Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out admin from helper list #93

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions commands/helper-list.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ exports.permissions = [
},
];

const filterOutAdmin = (member) => !member.roles.cache.some((role) => JSON.parse(process.env.ROLE).includes(role.id));

exports.execute = async (interaction) => {
await interaction.deferReply();

Expand All @@ -29,7 +31,9 @@ exports.execute = async (interaction) => {
let totalMember = 0;

allHelperRoles.forEach((helperRole) => {
totalMember += interaction.guild.roles.cache.get(helperRole.role_id).members.size;
totalMember += interaction.guild.roles.cache
.get(helperRole.role_id)
.members.filter((member) => filterOutAdmin(member)).size;
});

const allHelperEmbed = new MessageEmbed()
Expand All @@ -45,7 +49,8 @@ exports.execute = async (interaction) => {
const roleName = interaction.guild.roles.cache.get(helperRole.role_id).name;
const members = interaction.guild.roles.cache
.get(helperRole.role_id)
.members.map((member) => member.user.id);
.members.filter((member) => filterOutAdmin(member))
.map((member) => member.user.id);
const listMembers = members.length
? members.map((member) => `- <@${member}>`).join('\n')
: '- No one here :(';
Expand All @@ -62,7 +67,10 @@ exports.execute = async (interaction) => {
return await interaction.editReply({ content: 'Role not found!' });
}

const roleMemberIds = interaction.guild.roles.cache.get(role.id).members.map((member) => member.user.id);
const roleMemberIds = interaction.guild.roles.cache
.get(role.id)
.members.filter((member) => filterOutAdmin(member))
.map((member) => member.user.id);
const members = await Promise.all(
roleMemberIds.map(async (memberId) => {
const [firstMessage, lastMessage, lastMessageCountIn30Days] = await Promise.all([
Expand Down
Loading