async function calculateBasePermissions(
  guildOrId,
  memberOrId,
) {
  const guild = await getCached("guilds", guildOrId);
  const member = await getCached("members", memberOrId);
  if (!guild || !member) return "8";
  let permissions = 0n;
  // Calculate the role permissions bits, @everyone role is not in memberRoleIds so we need to pass guildId manualy
  permissions |= [
    ...member.guilds.get(guild.id)?.roles || [],
    guild.id,
  ].map((id) => guild.roles.get(id)?.permissions) // Removes any edge case undefined
    .filter((perm) => perm).reduce((bits, perms) => {
      bits |= BigInt(perms);
      return bits;
    }, 0n);
  // If the memberId is equal to the guild ownerId he automatically has every permission so we add ADMINISTRATOR permission
  if (guild.ownerId === member.id) permissions |= 8n;
  // Return the members permission bits as a string
  return permissions.toString();
}
/** Calculates the permissions this member has in the given guild */
Calculates the permissions this member has in the given guild
Calculates the permissions this member has in the given guild
async function calculateBasePermissions(
  guildOrId,
  memberOrId,
) {
  const guild = await getCached("guilds", guildOrId);
  const member = await getCached("members", memberOrId);
  if (!guild || !member) return "8";
  let permissions = 0n;
  permissions |= [
    ...member.guilds.get(guild.id)?.roles || [],
    guild.id,
  ].map((id) => guild.roles.get(id)?.permissions) 
    .filter((perm) => perm).reduce((bits, perms) => {
      bits |= BigInt(perms);
      return bits;
    }, 0n);
  if (guild.ownerId === member.id) permissions |= 8n;
  return permissions.toString();
}
async function calculateBasePermissions ( guildOrId , memberOrId , ) { const guild = await getCached ( "guilds" , guildOrId ) ; const member = await getCached ( "members" , memberOrId ) ; if ( ! guild || ! member ) return "8" ; let permissions = 0n ; permissions |= [ ... member . guilds . get ( guild . id ) ?. roles || [ ] , guild . id , ] . map ( ( id ) => guild . roles . get ( id ) ?. permissions ) . filter ( ( perm ) => perm ) . reduce ( ( bits , perms ) => { bits |= BigInt ( perms ) ; return bits ; } , 0n ) ; if ( guild . ownerId === member . id ) permissions |= 8n ; return permissions . toString ( ) ; }
Calculates the permissions this member has in the given guild
Calculates the permissions this member has in the given guild
// Calculate the role permissions bits, @everyone role is not in memberRoleIds so we need to pass guildId manualy // Removes any edge case undefined // If the memberId is equal to the guild ownerId he automatically has every permission so we add ADMINISTRATOR permission // Return the members permission bits as a string